/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.minierp.bean.EstablishmentBean;
import com.minierp.bean.OrderParameterCarrier;
import com.minierp.bean.QueryParameterCarrier;
import com.minierp.bean.QueryResult;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.AccessoryDao;
import com.minierp.dao.AdjustBillDao;
import com.minierp.dao.AreaDao;
import com.minierp.dao.BusinessBillDao;
import com.minierp.dao.CodeRuleDao;
import com.minierp.dao.CooperBillDao;
import com.minierp.dao.EstPriceDao;
import com.minierp.dao.EstablishmentCommunicateDao;
import com.minierp.dao.EstablishmentContactDao;
import com.minierp.dao.EstablishmentDao;
import com.minierp.dao.EstablishmentLevelDao;
import com.minierp.dao.EstablishmentTypeDao;
import com.minierp.dao.FinanceDetailDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.InBillDao;
import com.minierp.dao.MakeTypeDao;
import com.minierp.dao.OutBillDao;
import com.minierp.dao.PayBillDao;
import com.minierp.dao.ProductDao;
import com.minierp.dao.PurchaseBillDao;
import com.minierp.dao.QueryDao;
import com.minierp.dao.ReceiveBillDao;
import com.minierp.dao.SerialNumberDao;
import com.minierp.dao.StafferDao;
import com.minierp.dao.StockBalanceDao;
import com.minierp.dao.StockDao;
import com.minierp.dao.StorehouseDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.Area;
import com.minierp.model.BusinessBill;
import com.minierp.model.BusinessBillItem;
import com.minierp.model.CodeRule;
import com.minierp.model.CooperBill;
import com.minierp.model.CooperBillItem;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.Establishment;
import com.minierp.model.EstablishmentContact;
import com.minierp.model.EstablishmentLevel;
import com.minierp.model.EstablishmentType;
import com.minierp.model.MakeType;
import com.minierp.model.Product;
import com.minierp.model.PurchaseBill;
import com.minierp.model.PurchaseBillItem;
import com.minierp.model.Staffer;
import com.minierp.model.Storehouse;
import com.minierp.model.TallySet;
import com.minierp.model.User;
import com.minierp.service.BusinessBillService;
import com.minierp.service.CooperBillService;
import com.minierp.service.EstablishmentService;
import com.minierp.service.PurchaseBillService;
import com.minierp.view.EstablishmentListExcelView;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class EstablishmentMACtr extends MultiActionController {
	private EstablishmentDao establishmentDao;
	private EstablishmentContactDao establishmentContactDao;
	private EstablishmentTypeDao establishmentTypeDao;
	private EstablishmentLevelDao establishmentLevelDao;
	private AreaDao areaDao;
	private QueryDao queryDao;
	private BusinessBillDao businessBillDao;
	private PurchaseBillDao purchaseBillDao;
	private CooperBillDao cooperBillDao;
	private AdjustBillDao adjustBillDao;
	private ReceiveBillDao receiveBillDao;
	private InBillDao inBillDao;
	private OutBillDao outBillDao;
	private EstablishmentCommunicateDao establishmentCommunicateDao;
	private AccessoryDao accessoryDao;
	private FinanceDetailDao financeDetailDao;
	private EstPriceDao estPriceDao;
	private PayBillDao payBillDao;
	private TallySetDao tallySetDao;
	private StafferDao stafferDao;
	private MakeTypeDao makeTypeDao;
	private ProductDao productDao;
	private StockDao stockDao;
	private StorehouseDao storehouseDao;
	private StockBalanceDao stockBalanceDao;
	private CodeRuleDao codeRuleDao;
	private SerialNumberDao serialNumberDao;
	private IdGenerator idGenerator;
	private EstablishmentService establishmentService;
	private BusinessBillService businessBillService;
	private CooperBillService cooperBillService;
	private PurchaseBillService purchaseBillService;
	private String clientListView;
	private String providerListView;
	private String cooperatorListView;
	private String listForSelectView;
	private String listForPriceView;
	private String listForCooperPriceView;
	private String manageListView;
	private String checkView;
	private String contactListForSelectView;
	private String moveFormView;
	private String moveSimpleFormView;
	private String moveSuccessView;
	private String changeTsFormView;
	private String contactSelectForSmsView;
	private String logListView;
	private String logSearchResultView;
	private String impoFormView;
	private String begiImpoFormView;

	public StorehouseDao getStorehouseDao() {
		return this.storehouseDao;
	}

	public void setStorehouseDao(StorehouseDao storehouseDao) {
		this.storehouseDao = storehouseDao;
	}

	public MakeTypeDao getMakeTypeDao() {
		return this.makeTypeDao;
	}

	public void setMakeTypeDao(MakeTypeDao makeTypeDao) {
		this.makeTypeDao = makeTypeDao;
	}

	public ProductDao getProductDao() {
		return this.productDao;
	}

	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	public StockDao getStockDao() {
		return this.stockDao;
	}

	public void setStockDao(StockDao stockDao) {
		this.stockDao = stockDao;
	}

	public StockBalanceDao getStockBalanceDao() {
		return this.stockBalanceDao;
	}

	public void setStockBalanceDao(StockBalanceDao stockBalanceDao) {
		this.stockBalanceDao = stockBalanceDao;
	}

	public BusinessBillService getBusinessBillService() {
		return this.businessBillService;
	}

	public void setBusinessBillService(BusinessBillService businessBillService) {
		this.businessBillService = businessBillService;
	}

	public CooperBillService getCooperBillService() {
		return this.cooperBillService;
	}

	public void setCooperBillService(CooperBillService cooperBillService) {
		this.cooperBillService = cooperBillService;
	}

	public PurchaseBillService getPurchaseBillService() {
		return this.purchaseBillService;
	}

	public void setPurchaseBillService(PurchaseBillService purchaseBillService) {
		this.purchaseBillService = purchaseBillService;
	}

	public String getBegiImpoFormView() {
		return this.begiImpoFormView;
	}

	public void setBegiImpoFormView(String begiImpoFormView) {
		this.begiImpoFormView = begiImpoFormView;
	}

	public StafferDao getStafferDao() {
		return this.stafferDao;
	}

	public void setStafferDao(StafferDao stafferDao) {
		this.stafferDao = stafferDao;
	}

	public CodeRuleDao getCodeRuleDao() {
		return this.codeRuleDao;
	}

	public void setCodeRuleDao(CodeRuleDao codeRuleDao) {
		this.codeRuleDao = codeRuleDao;
	}

	public SerialNumberDao getSerialNumberDao() {
		return this.serialNumberDao;
	}

	public void setSerialNumberDao(SerialNumberDao serialNumberDao) {
		this.serialNumberDao = serialNumberDao;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public String getImpoFormView() {
		return this.impoFormView;
	}

	public void setImpoFormView(String impoFormView) {
		this.impoFormView = impoFormView;
	}

	public String getLogSearchResultView() {
		return this.logSearchResultView;
	}

	public void setLogSearchResultView(String logSearchResultView) {
		this.logSearchResultView = logSearchResultView;
	}

	public String getLogListView() {
		return this.logListView;
	}

	public void setLogListView(String logListView) {
		this.logListView = logListView;
	}

	public PurchaseBillDao getPurchaseBillDao() {
		return this.purchaseBillDao;
	}

	public void setPurchaseBillDao(PurchaseBillDao purchaseBillDao) {
		this.purchaseBillDao = purchaseBillDao;
	}

	public CooperBillDao getCooperBillDao() {
		return this.cooperBillDao;
	}

	public void setCooperBillDao(CooperBillDao cooperBillDao) {
		this.cooperBillDao = cooperBillDao;
	}

	public String getMoveFormView() {
		return this.moveFormView;
	}

	public void setMoveFormView(String moveFormView) {
		this.moveFormView = moveFormView;
	}

	public String getMoveSuccessView() {
		return this.moveSuccessView;
	}

	public void setMoveSuccessView(String moveSuccessView) {
		this.moveSuccessView = moveSuccessView;
	}

	public ModelAndView handleList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String type = request.getParameter("type");
		if (type != null && type.equals("PROVIDER")) {
			if (!EncCommonHelper.checkPrivilege(request, "BASE_PROV")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null && type.equals("COOPERATOR")) {
			if (!EncCommonHelper.checkPrivilege(request, "BASE_COOP")) {
				throw new PermissionDennyException("Permission Denny");
			}
		} else if (type != null && type.equals("CLIENT")
				&& !EncCommonHelper.checkPrivilege(request, "BASE_CLIE")) {
			throw new PermissionDennyException("Permission Denny");
		}

		String contentType = request.getParameter("content_type");
		String searchType = request.getParameter("search_type");
		String searchKey = "";
		String managerName = "";
		String phone = "";
		String addr = "";
		String mark = "";
		String estTypeId = "0";
		String estLevId = "0";
		String areaId = "0";
		String tsId = "0";
		String startDateStr = "";
		String endDateStr = "";
		Date startDate = null;
		Date endDate = null;
		Date busiStart = null;
		Date busiEnd = null;
		Date commStart = null;
		Date commEnd = null;
		ModelAndView mv;
		if (type.equals("PROVIDER")) {
			mv = new ModelAndView(this.providerListView);
		} else if (type.equals("COOPERATOR")) {
			mv = new ModelAndView(this.cooperatorListView);
		} else {
			mv = new ModelAndView(this.clientListView);
		}

		mv.addObject("searchKey", request.getParameter("search_key"));
		mv.addObject("managerName", request.getParameter("manager_name"));
		mv.addObject("phone", request.getParameter("phone"));
		mv.addObject("addr", request.getParameter("addr"));
		mv.addObject("mark", request.getParameter("mark"));
		mv.addObject("estType", request.getParameter("est_type"));
		mv.addObject("estLev", request.getParameter("est_lev"));
		mv.addObject("areaId", request.getParameter("area_id"));
		mv.addObject("startDate", request.getParameter("start_date"));
		mv.addObject("endDate", request.getParameter("end_date"));
		mv.addObject("tsId", request.getParameter("ts_id"));
		mv.addObject("busi", request.getParameter("busi"));
		mv.addObject("comm", request.getParameter("comm"));
		mv.addObject("searchType", searchType);
		mv.addObject("type", type);
		boolean checkTs = true;
		EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (ent.getBaseTs() == null || !ent.getBaseTs().equals("Y")) {
			checkTs = false;
		}

		List myTsList = PageHelper.getTallySetList(this.tallySetDao, ub);
		if (searchType != null && !searchType.equals("")) {
			if (searchType.equals("2")) {
				searchKey = request.getParameter("search_key");
			} else {
				String perPageNum = request.getParameter("cb_sk");
				String total = request.getParameter("cb_manager");
				String pageno = request.getParameter("cb_phone");
				String startIndex = request.getParameter("cb_addr");
				String list = request.getParameter("cb_mark");
				String arr = request.getParameter("cb_est_type");
				String bean = request.getParameter("cb_est_lev");
				String e = request.getParameter("cb_area");
				String i = request.getParameter("cb_ts");
				String cbCreDate = request.getParameter("cb_cre_date");
				String cbBusi = request.getParameter("cb_busi");
				String cbComm = request.getParameter("cb_comm");
				if (perPageNum != null && perPageNum.equals("1")) {
					searchKey = request.getParameter("search_key");
					mv.addObject("cbSK", perPageNum);
				}

				if (total != null && total.equals("1")) {
					managerName = request.getParameter("manager_name");
					mv.addObject("cbManager", total);
				}

				if (pageno != null && pageno.equals("1")) {
					phone = request.getParameter("phone");
					mv.addObject("cbPhone", pageno);
				}

				if (startIndex != null && startIndex.equals("1")) {
					addr = request.getParameter("addr");
					mv.addObject("cbAddr", startIndex);
				}

				if (list != null && list.equals("1")) {
					mark = request.getParameter("mark");
					mv.addObject("cbMark", list);
				}

				if (arr != null && arr.equals("1")) {
					estTypeId = request.getParameter("est_type");
					mv.addObject("cbEstType", arr);
				}

				if (bean != null && bean.equals("1")) {
					estLevId = request.getParameter("est_lev");
					mv.addObject("cbEstLev", bean);
				}

				if (e != null && e.equals("1")) {
					areaId = request.getParameter("area_id");
					mv.addObject("cbArea", e);
				}

				Calendar c = Calendar.getInstance();
				Date now = new Date();
				String sf;
				if (cbBusi != null && cbBusi.equals("1")) {
					sf = request.getParameter("busi");
					if (sf.equals("1")) {
						c.setTime(now);
						c.add(2, -3);
						busiStart = c.getTime();
						c.setTime(now);
						c.add(2, -1);
						busiEnd = c.getTime();
					} else if (sf.equals("3")) {
						c.setTime(now);
						c.add(2, -6);
						busiStart = c.getTime();
						c.setTime(now);
						c.add(2, -3);
						busiEnd = c.getTime();
					} else if (sf.equals("6")) {
						c.setTime(now);
						c.add(2, -12);
						busiStart = c.getTime();
						c.setTime(now);
						c.add(2, -6);
						busiEnd = c.getTime();
					} else if (sf.equals("12")) {
						c.setTime(now);
						c.add(2, -12);
						busiEnd = c.getTime();
					}

					mv.addObject("cbBusi", cbBusi);
				}

				if (cbComm != null && cbComm.equals("1")) {
					sf = request.getParameter("comm");
					if (sf.equals("1")) {
						c.setTime(now);
						c.add(2, -3);
						commStart = c.getTime();
						c.setTime(now);
						c.add(2, -1);
						commEnd = c.getTime();
					} else if (sf.equals("3")) {
						c.setTime(now);
						c.add(2, -6);
						commStart = c.getTime();
						c.setTime(now);
						c.add(2, -3);
						commEnd = c.getTime();
					} else if (sf.equals("6")) {
						c.setTime(now);
						c.add(2, -12);
						commStart = c.getTime();
						c.setTime(now);
						c.add(2, -6);
						commEnd = c.getTime();
					} else if (sf.equals("12")) {
						c.setTime(now);
						c.add(2, -12);
						commEnd = c.getTime();
					}

					mv.addObject("cbComm", cbComm);
				}

				if (cbCreDate != null && cbCreDate.equals("1")) {
					SimpleDateFormat arg55 = new SimpleDateFormat("yyyy-MM-dd");
					startDateStr = request.getParameter("start_date");
					endDateStr = request.getParameter("end_date");
					startDate = arg55.parse(startDateStr);
					endDate = arg55.parse(EncCommonHelper.getNextDateStr(
							endDateStr, "yyyy-MM-dd"));
					mv.addObject("cbCreDate", cbCreDate);
				}

				if (checkTs && i != null && i.equals("1")) {
					tsId = request.getParameter("ts_id");
					if (tsId.equals("DF_TS_ID")) {
						tsId = String.valueOf(ub.getUser().getDfTsId());
					}

					mv.addObject("tsId", tsId);
					mv.addObject("cbTs", i);
				}
			}
		} else {
			searchType = "1";
			if (checkTs) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
				mv.addObject("tsId", tsId);
				mv.addObject("cbTs", "1");
			}
		}

		int arg42;
		if (contentType != null && contentType.equals("EXCEL")) {
			arg42 = this.establishmentDao.getListCount(type, searchKey,
					managerName, phone, addr, mark, Long.parseLong(estTypeId),
					Long.parseLong(estLevId), Long.parseLong(areaId),
					startDate, endDate, busiStart, busiEnd, commStart, commEnd,
					checkTs, Long.parseLong(tsId), ub, true);
			List arg44 = this.establishmentDao.getList(type, searchKey,
					managerName, phone, addr, mark, Long.parseLong(estTypeId),
					Long.parseLong(estLevId), Long.parseLong(areaId),
					startDate, endDate, busiStart, busiEnd, commStart, commEnd,
					checkTs, Long.parseLong(tsId), ub, true, 0, arg42);
			List arg46 = this.establishmentContactDao
					.getList(type, searchKey, managerName, phone, addr, mark,
							Long.parseLong(estTypeId),
							Long.parseLong(estLevId), Long.parseLong(areaId),
							startDate, endDate, checkTs, Long.parseLong(tsId),
							ub, true);
			HashMap arg48 = new HashMap();
			arg48.put("type", type);
			arg48.put("list", arg44);
			arg48.put("contList", arg46);
			arg48.put("typeList", this.establishmentTypeDao.getList(false));
			arg48.put("leveList", this.establishmentLevelDao.getList(false));
			arg48.put("areaList", this.areaDao.getList(false));
			arg48.put("tsList", this.tallySetDao.getList(false));
			EstablishmentListExcelView arg50 = new EstablishmentListExcelView();
			return new ModelAndView(arg50, arg48);
		} else {
			arg42 = EncCommonHelper.getPageSize(request);
			int arg43 = this.establishmentDao.getListCount(type, searchKey,
					managerName, phone, addr, mark, Long.parseLong(estTypeId),
					Long.parseLong(estLevId), Long.parseLong(areaId),
					startDate, endDate, busiStart, busiEnd, commStart, commEnd,
					checkTs, Long.parseLong(tsId), ub, true);
			int arg45 = EncCommonHelper.getCurrentPageIndex(request, arg43,
					arg42);
			int arg47 = (arg45 - 1) * arg42;
			List arg49 = this.establishmentDao.getList(type, searchKey,
					managerName, phone, addr, mark, Long.parseLong(estTypeId),
					Long.parseLong(estLevId), Long.parseLong(areaId),
					startDate, endDate, busiStart, busiEnd, commStart, commEnd,
					checkTs, Long.parseLong(tsId), ub, true, arg47, arg42);
			ArrayList arg51 = new ArrayList();

			for (int arg54 = 0; arg54 < arg49.size(); ++arg54) {
				EstablishmentBean arg52 = new EstablishmentBean();
				Establishment arg53 = (Establishment) arg49.get(arg54);
				arg52.setEstablishment(arg53);
				arg51.add(arg52);
			}

			mv.addObject("qr", EncCommonHelper.parseQueryResult(arg51, arg43,
					arg42, arg45));
			mv.addObject("tsList", this.tallySetDao.getList(false));
			mv.addObject("areaList", this.areaDao.getList(true));
			mv.addObject("estTypeList", this.establishmentTypeDao.getList(true));
			mv.addObject("estLevelList",
					this.establishmentLevelDao.getList(true));
			mv.addObject("myTsList", myTsList);
			mv.addObject("checkTs", ent.getBaseTs());
			return mv;
		}
	}

	public ModelAndView handleDelete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String returnUrl = request.getParameter("from_url");
		ModelAndView mv = new ModelAndView("redirect:" + returnUrl);
		String id = request.getParameter("id");
		Establishment b = (Establishment) this.establishmentDao.get(
				Establishment.class, Long.parseLong(id));
		if (b.getEstType().equals("CLIENT")
				&& this.businessBillDao.isHasBill(Long.parseLong(id))) {
			EncCommonHelper.setAlertMessage(request, "客户已经有业务单存在，不能删除！");
		} else if (b.getEstType().equals("PROVIDER")
				&& this.purchaseBillDao.isHasBill(Long.parseLong(id))) {
			EncCommonHelper.setAlertMessage(request, "供应商已经有采购单存在，不能删除！");
		} else if (b.getEstType().equals("COOPERATOR")
				&& this.cooperBillDao.isHasBill(Long.parseLong(id))) {
			EncCommonHelper.setAlertMessage(request, "外协商已经有外协单存在，不能删除！");
		} else {
			if (b != null) {
				b.setEnabled("N");
				this.establishmentDao.update(b);
			}

			EncCommonHelper.setAlertMessage(request, "删除成功！");
		}

		return mv;
	}

	public ModelAndView handlePause(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String returnUrl = request.getParameter("from_url");
		ModelAndView mv = new ModelAndView("redirect:" + returnUrl);
		String id = request.getParameter("id");
		String flag = request.getParameter("flag");
		Establishment b = (Establishment) this.establishmentDao.get(
				Establishment.class, Long.parseLong(id));
		if (b != null) {
			b.setStatus(flag);
			this.establishmentDao.update(b);
		}

		EncCommonHelper.setAlertMessage(request, "设置成功！");
		return mv;
	}

	public ModelAndView handleListForSelect(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.listForSelectView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String type = request.getParameter("type");
		String searchKey = request.getParameter("search_key");
		String typeId = request.getParameter("type_id");
		String levelId = request.getParameter("level_id");
		String areaId = request.getParameter("area_id");
		String tsId = request.getParameter("ts_id");
		String showAll = request.getParameter("show_all");
		String orderType = request.getParameter("order_type");
		if (typeId == null || typeId.equals("")) {
			typeId = "0";
		}

		if (levelId == null || levelId.equals("")) {
			levelId = "0";
		}

		if (areaId == null || areaId.equals("")) {
			areaId = "0";
		}

		if (tsId != null && !tsId.equals("")) {
			if (tsId.equals("DF_TS_ID")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
				if (tsId.equals("0")) {
					tsId = "-1";
				}
			}
		} else {
			tsId = "0";
		}

		if (showAll == null) {
			showAll = "";
		}

		boolean checkTs = true;
		EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
		long managerId = 0L;
		if (showAll.equals("Y")) {
			checkTs = false;
		} else {
			if (ent.getBaseTs() == null || !ent.getBaseTs().equals("Y")) {
				checkTs = false;
			}

			if (showAll.equals("S")
					&& EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
				managerId = ub.getStaffer().getId();
			}
		}

		int perPageNum = EncCommonHelper.getPageSize(request);
		int total = this.establishmentDao.getListCount(type,
				Long.parseLong(typeId), Long.parseLong(levelId),
				Long.parseLong(areaId), searchKey, managerId, checkTs,
				Long.parseLong(tsId), ub, true);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total,
				perPageNum);
		int startIndex = (pageno - 1) * perPageNum;
		List list = this.establishmentDao.getList(type, Long.parseLong(typeId),
				Long.parseLong(levelId), Long.parseLong(areaId), searchKey,
				managerId, checkTs, Long.parseLong(tsId), ub, true, orderType,
				startIndex, perPageNum);
		ArrayList arr = new ArrayList();

		for (int i = 0; i < list.size(); ++i) {
			EstablishmentBean bean = new EstablishmentBean();
			bean.setEstablishment((Establishment) list.get(i));
			if (bean.getEstablishment().getEstType().equals("CLIENT")) {
				if (ent.getSelectContact() != null
						&& ent.getSelectContact().equals("ALL")) {
					bean.setCanManage("Y");
				} else if (bean.getEstablishment().getManagerId() == ub
						.getStaffer().getId()) {
					bean.setCanManage("Y");
				} else {
					Staffer s = (Staffer) this.establishmentDao.get(
							Staffer.class, bean.getEstablishment()
									.getManagerId());
					if (s != null
							&& s.getSuperiorIdStr() != null
							&& s.getSuperiorIdStr().indexOf(
									";" + ub.getStaffer().getId() + ";") != -1) {
						bean.setCanManage("Y");
					} else {
						bean.setCanManage("N");
					}
				}
			}

			arr.add(bean);
		}

		mv.addObject("qr", EncCommonHelper.parseQueryResult(arr, total,
				perPageNum, pageno));
		mv.addObject("areaList", this.areaDao.getList(true));
		mv.addObject("estTypeList", this.establishmentTypeDao.getList(true));
		mv.addObject("estLevelList", this.establishmentLevelDao.getList(true));
		mv.addObject("searchKey", searchKey);
		mv.addObject("type", type);
		mv.addObject("typeId", typeId);
		mv.addObject("levelId", levelId);
		mv.addObject("areaId", areaId);
		mv.addObject("tsId", tsId);
		mv.addObject("showAll", showAll);
		mv.addObject("orderType", orderType);
		return mv;
	}

	public ModelAndView handleListForPrice(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String type = request.getParameter("type");
		long managerId = 0L;
		if (EncCommonHelper.checkPurePrivilege(request, "BUSI_SELF")) {
			managerId = ub.getStaffer().getId();
		}

		String searchKey = request.getParameter("search_key");
		String typeId = request.getParameter("type_id");
		String levelId = request.getParameter("level_id");
		String areaId = request.getParameter("area_id");
		ModelAndView mv;
		if (type.equals("CLIENT")) {
			mv = new ModelAndView(this.listForPriceView);
		} else {
			mv = new ModelAndView(this.listForCooperPriceView);
		}

		if (typeId == null || typeId.equals("")) {
			typeId = "0";
		}

		if (levelId == null || levelId.equals("")) {
			levelId = "0";
		}

		if (areaId == null || areaId.equals("")) {
			areaId = "0";
		}

		String tsId = "0";
		boolean checkTs = true;
		EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
		if (ent.getBaseTs() != null && ent.getBaseTs().equals("Y")) {
			List perPageNum = PageHelper.getTallySetList(this.tallySetDao, ub);
			tsId = request.getParameter("ts_id");
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			mv.addObject("tsId", tsId);
			mv.addObject("tsList", perPageNum);
		} else {
			checkTs = false;
		}

		int arg22 = EncCommonHelper.getPageSize(request);
		int total = this.establishmentDao.getListCount(type,
				Long.parseLong(typeId), Long.parseLong(levelId),
				Long.parseLong(areaId), searchKey, managerId, checkTs,
				Long.parseLong(tsId), ub, true);
		int pageno = EncCommonHelper.getCurrentPageIndex(request, total, arg22);
		int startIndex = (pageno - 1) * arg22;
		List list = this.establishmentDao.getList(type, Long.parseLong(typeId),
				Long.parseLong(levelId), Long.parseLong(areaId), searchKey,
				managerId, checkTs, Long.parseLong(tsId), ub, true, "",
				startIndex, arg22);
		ArrayList arr = new ArrayList();

		for (int i = 0; i < list.size(); ++i) {
			EstablishmentBean bean = new EstablishmentBean();
			bean.setEstablishment((Establishment) list.get(i));
			arr.add(bean);
		}

		mv.addObject("qr",
				EncCommonHelper.parseQueryResult(arr, total, arg22, pageno));
		mv.addObject("areaList", this.areaDao.getList(true));
		mv.addObject("estTypeList", this.establishmentTypeDao.getList(true));
		mv.addObject("estLevelList", this.establishmentLevelDao.getList(true));
		mv.addObject("type", type);
		mv.addObject("searchKey", searchKey);
		mv.addObject("typeId", typeId);
		mv.addObject("levelId", levelId);
		mv.addObject("areaId", areaId);
		mv.addObject("checkTs", ent.getBaseTs());
		return mv;
	}

	public ModelAndView handleCheck(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.checkView);
		String type = request.getParameter("type");
		String id = request.getParameter("id");
		String checkKey = request.getParameter("check_key");
		if (id == null || id.equals("")) {
			id = "0";
		}

		List list = this.establishmentDao.getList(checkKey, type,
				Long.parseLong(id));
		mv.addObject("list", list);
		mv.addObject("checkKey", checkKey);
		mv.addObject("type", type);
		return mv;
	}

	public ModelAndView handleManageList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.manageListView);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		if (ub.getStaffer() != null) {
			String searchType = request.getParameter("search_type");
			String type = request.getParameter("type");
			String order = request.getParameter("order");
			String searchKey = "";
			String managerName = "";
			String phone = "";
			String addr = "";
			String estType = "0";
			String estLev = "0";
			String areaId = "0";
			String tsId = "0";
			String startDateStr = "";
			String endDateStr = "";
			Date startDate = null;
			Date endDate = null;
			Date busiStart = null;
			Date busiEnd = null;
			Date commStart = null;
			Date commEnd = null;
			mv.addObject("searchKey", request.getParameter("search_key"));
			mv.addObject("managerName", request.getParameter("manager_name"));
			mv.addObject("phone", request.getParameter("phone"));
			mv.addObject("addr", request.getParameter("addr"));
			mv.addObject("estType", request.getParameter("est_type"));
			mv.addObject("estLev", request.getParameter("est_lev"));
			mv.addObject("areaId", request.getParameter("area_id"));
			mv.addObject("startDate", request.getParameter("start_date"));
			mv.addObject("endDate", request.getParameter("end_date"));
			mv.addObject("busi", request.getParameter("busi"));
			mv.addObject("comm", request.getParameter("comm"));
			mv.addObject("tsId", request.getParameter("ts_id"));
			mv.addObject("type", type);
			mv.addObject("order", order);
			boolean checkTs = true;
			EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
			if (ent.getBaseTs() == null || !ent.getBaseTs().equals("Y")) {
				checkTs = false;
			}

			List myTsList = PageHelper.getTallySetList(this.tallySetDao, ub);
			String webSite;
			if (searchType != null && !searchType.equals("")) {
				if (searchType.equals("2")) {
					searchKey = request.getParameter("search_key");
				} else {
					String perPageNum = request.getParameter("cb_sk");
					String total = request.getParameter("cb_manager");
					String pageno = request.getParameter("cb_phone");
					String startIndex = request.getParameter("cb_addr");
					String list = request.getParameter("cb_est_type");
					String arr = request.getParameter("cb_est_lev");
					String i = request.getParameter("cb_area");
					String bean = request.getParameter("cb_cre_date");
					String e = request.getParameter("cb_ts");
					webSite = request.getParameter("cb_busi");
					String cbComm = request.getParameter("cb_comm");
					if (perPageNum != null && perPageNum.equals("1")) {
						searchKey = request.getParameter("search_key");
						mv.addObject("cbSK", perPageNum);
					}

					if (total != null && total.equals("1")) {
						managerName = request.getParameter("manager_name");
						mv.addObject("cbManager", total);
					}

					if (pageno != null && pageno.equals("1")) {
						phone = request.getParameter("phone");
						mv.addObject("cbPhone", pageno);
					}

					if (startIndex != null && startIndex.equals("1")) {
						addr = request.getParameter("addr");
						mv.addObject("cbAddr", startIndex);
					}

					if (list != null && list.equals("1")) {
						estType = request.getParameter("est_type");
						mv.addObject("cbEstType", list);
					}

					if (arr != null && arr.equals("1")) {
						estLev = request.getParameter("est_lev");
						mv.addObject("cbEstLev", arr);
					}

					if (i != null && i.equals("1")) {
						areaId = request.getParameter("area_id");
						mv.addObject("cbArea", i);
					}

					Calendar c = Calendar.getInstance();
					Date now = new Date();
					String sf;
					if (webSite != null && webSite.equals("1")) {
						sf = request.getParameter("busi");
						if (sf.equals("1")) {
							c.setTime(now);
							c.add(2, -3);
							busiStart = c.getTime();
							c.setTime(now);
							c.add(2, -1);
							busiEnd = c.getTime();
						} else if (sf.equals("3")) {
							c.setTime(now);
							c.add(2, -6);
							busiStart = c.getTime();
							c.setTime(now);
							c.add(2, -3);
							busiEnd = c.getTime();
						} else if (sf.equals("6")) {
							c.setTime(now);
							c.add(2, -12);
							busiStart = c.getTime();
							c.setTime(now);
							c.add(2, -6);
							busiEnd = c.getTime();
						} else if (sf.equals("12")) {
							c.setTime(now);
							c.add(2, -12);
							busiEnd = c.getTime();
						}

						mv.addObject("cbBusi", webSite);
					}

					if (cbComm != null && cbComm.equals("1")) {
						sf = request.getParameter("comm");
						if (sf.equals("1")) {
							c.setTime(now);
							c.add(2, -3);
							commStart = c.getTime();
							c.setTime(now);
							c.add(2, -1);
							commEnd = c.getTime();
						} else if (sf.equals("3")) {
							c.setTime(now);
							c.add(2, -6);
							commStart = c.getTime();
							c.setTime(now);
							c.add(2, -3);
							commEnd = c.getTime();
						} else if (sf.equals("6")) {
							c.setTime(now);
							c.add(2, -12);
							commStart = c.getTime();
							c.setTime(now);
							c.add(2, -6);
							commEnd = c.getTime();
						} else if (sf.equals("12")) {
							c.setTime(now);
							c.add(2, -12);
							commEnd = c.getTime();
						}

						mv.addObject("cbComm", cbComm);
					}

					if (bean != null && bean.equals("1")) {
						SimpleDateFormat arg49 = new SimpleDateFormat(
								"yyyy-MM-dd");
						startDateStr = request.getParameter("start_date");
						endDateStr = request.getParameter("end_date");
						startDate = arg49.parse(startDateStr);
						endDate = arg49.parse(EncCommonHelper.getNextDateStr(
								endDateStr, "yyyy-MM-dd"));
						mv.addObject("cbCreDate", bean);
					}

					if (checkTs && e != null && e.equals("1")) {
						tsId = request.getParameter("ts_id");
						if (tsId.equals("DF_TS_ID")) {
							tsId = String.valueOf(ub.getUser().getDfTsId());
						}

						mv.addObject("tsId", tsId);
						mv.addObject("cbTs", e);
					}
				}
			} else {
				searchType = "1";
				if (checkTs) {
					tsId = String.valueOf(ub.getUser().getDfTsId());
					mv.addObject("tsId", tsId);
					mv.addObject("cbTs", "1");
				}
			}

			mv.addObject("searchType", searchType);
			int arg40 = EncCommonHelper.getPageSize(request);
			int arg41 = this.establishmentDao.getManageListCount(type, ub
					.getStaffer().getId(), searchKey, managerName, phone, addr,
					Long.parseLong(estType), Long.parseLong(estLev), Long
							.parseLong(areaId), startDate, endDate, busiStart,
					busiEnd, commStart, commEnd, checkTs, Long.parseLong(tsId),
					ub);
			int arg42 = EncCommonHelper.getCurrentPageIndex(request, arg41,
					arg40);
			int arg43 = (arg42 - 1) * arg40;
			List arg44 = this.establishmentDao.getManageList(type, ub
					.getStaffer().getId(), searchKey, managerName, phone, addr,
					Long.parseLong(estType), Long.parseLong(estLev), Long
							.parseLong(areaId), startDate, endDate, busiStart,
					busiEnd, commStart, commEnd, checkTs, Long.parseLong(tsId),
					ub, order, arg43, arg40);
			ArrayList arg45 = new ArrayList();

			for (int arg46 = 0; arg46 < arg44.size(); ++arg46) {
				EstablishmentBean arg47 = new EstablishmentBean();
				Establishment arg48 = (Establishment) arg44.get(arg46);
				arg47.setEstablishment(arg48);
				webSite = arg48.getWebSite();
				if (webSite != null && !webSite.trim().equals("")
						&& !webSite.toLowerCase().startsWith("http://")) {
					webSite = "http://" + webSite.trim();
				}

				arg47.setWebSite(webSite);
				arg45.add(arg47);
			}

			mv.addObject("qr", EncCommonHelper.parseQueryResult(arg45, arg41,
					arg40, arg42));
			mv.addObject("areaList", this.areaDao.getList(true));
			mv.addObject("estTypeList", this.establishmentTypeDao.getList(true));
			mv.addObject("estLevelList",
					this.establishmentLevelDao.getList(true));
			mv.addObject("myTsList", myTsList);
			mv.addObject("checkTs", ent.getBaseTs());
		}

		return mv;
	}

	public ModelAndView handleContactListForSelect(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.contactListForSelectView);
		long estId = Long.parseLong(request.getParameter("est_id"));
		mv.addObject("establishment",
				this.establishmentDao.get(Establishment.class, estId));
		mv.addObject("contactList", this.establishmentContactDao.getList(estId));
		return mv;
	}

	public ModelAndView handleMoveForm(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "CLIE_MOVE")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String type = request.getParameter("type");
			String estType = request.getParameter("est_type");
			ModelAndView mv;
			if (type != null && type.equals("MULTI")) {
				mv = new ModelAndView(this.moveSimpleFormView);
				mv.addObject("idStr", request.getParameter("id_str"));
			} else {
				mv = new ModelAndView(this.moveFormView);
			}

			mv.addObject("estType", estType);
			return mv;
		}
	}

	public ModelAndView handleMove(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String type = request.getParameter("type");
		String estType = request.getParameter("est_type");
		String toManagerId = request.getParameter("to_mng_id");
		Staffer s = (Staffer) this.establishmentDao.get(Staffer.class,
				Long.parseLong(toManagerId));
		String toManagerName = "";
		if (s != null) {
			toManagerName = s.getStafferName();
		}

		ModelAndView mv;
		String fromManagerId;
		if (type != null && type.equals("MULTI")) {
			fromManagerId = request.getParameter("id_str");
			String[] ids = fromManagerId.split(";");
			long[] idArr = new long[ids.length];

			for (int i = 0; i < ids.length; ++i) {
				idArr[i] = Long.parseLong(ids[i]);
			}

			this.establishmentDao.update(idArr, Long.parseLong(toManagerId),
					toManagerName, estType);
			mv = new ModelAndView("redirect:/ModalDialogSuccess.ihtm");
			mv.addObject("returnValue", String.valueOf(ids.length));
		} else {
			fromManagerId = request.getParameter("from_mng_id");
			this.establishmentDao.update(Long.parseLong(fromManagerId),
					Long.parseLong(toManagerId), toManagerName, estType);
			mv = new ModelAndView(this.moveSuccessView);
			mv.addObject("alertType", "SHOW");
		}

		EncCommonHelper.setAlertMessage(request, "移交成功！");
		return mv;
	}

	public ModelAndView handleCorporate(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		boolean hasPrivilege = false;
		if (ub != null && ub.getUser() != null) {
			User type = ub.getUser();
			if (type.getUserType() == 1) {
				hasPrivilege = true;
			}
		}

		if (!hasPrivilege) {
			throw new Exception("Permission deny!");
		} else {
			String arg9 = request.getParameter("type");
			String idStr = request.getParameter("id_str");
			String[] ids = idStr.split(";");
			if (ids.length > 1) {
				long[] mv = new long[ids.length];

				for (int i = 0; i < ids.length; ++i) {
					mv[i] = Long.parseLong(ids[i]);
				}

				if (arg9.equals("CLIENT")) {
					this.establishmentService.txClientCorporate(mv,
							this.establishmentDao, this.businessBillDao,
							this.adjustBillDao, this.receiveBillDao,
							this.inBillDao, this.outBillDao,
							this.establishmentContactDao,
							this.establishmentCommunicateDao,
							this.financeDetailDao, this.accessoryDao,
							this.estPriceDao);
				} else if (arg9.equals("COOPERATOR")) {
					this.establishmentService.txCooperatorCorporate(mv,
							this.establishmentDao, this.cooperBillDao,
							this.adjustBillDao, this.payBillDao,
							this.inBillDao, this.outBillDao,
							this.establishmentContactDao,
							this.establishmentCommunicateDao,
							this.financeDetailDao, this.accessoryDao,
							this.estPriceDao);
				} else if (arg9.equals("PROVIDER")) {
					this.establishmentService.txProviderCorporate(mv,
							this.establishmentDao, this.purchaseBillDao,
							this.adjustBillDao, this.payBillDao,
							this.inBillDao, this.outBillDao,
							this.establishmentContactDao,
							this.establishmentCommunicateDao,
							this.financeDetailDao, this.accessoryDao,
							this.estPriceDao);
				}
			}

			ModelAndView arg10 = new ModelAndView(
					"redirect:/ModalDialogSuccess.ihtm");
			arg10.addObject("returnValue", String.valueOf(ids.length));
			EncCommonHelper.setAlertMessage(request, "合并成功！");
			return arg10;
		}
	}

	public ModelAndView handleContactSelectForSms(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.contactSelectForSmsView);
		String estObjName = "com.minierp.model.Establishment";
		String estObjShortName = "e";
		String conObjName = "com.minierp.model.EstablishmentContact";
		String conObjShortName = "c";
		HashMap shortNameMap = new HashMap();
		String[] retObjs = new String[]{conObjShortName};
		Vector qpVe = new Vector();
		shortNameMap.put(conObjName, conObjShortName);
		shortNameMap.put(estObjName, estObjShortName);
		QueryParameterCarrier qp = new QueryParameterCarrier();
		qp.objectName = estObjName;
		qp.propertyName = "id";
		qp.value = " c.estId=e.id";
		qp.dataType = 6;
		qp.logicType = 10;
		qpVe.add(qp);
		qp = new QueryParameterCarrier();
		qp.objectName = conObjName;
		qp.propertyName = "mobile";
		qp.value = " (c.mobile is not null) and c.mobile!=\'\'";
		qp.dataType = 6;
		qp.logicType = 10;
		qpVe.add(qp);
		String estType = request.getParameter("est_type");
		String searchType = request.getParameter("search_type");
		String key = request.getParameter("key");
		if (searchType == null) {
			searchType = "";
		}

		qp = new QueryParameterCarrier();
		qp.objectName = estObjName;
		qp.propertyName = "estType";
		qp.value = estType;
		qp.dataType = 1;
		qp.logicType = 1;
		qpVe.add(qp);
		boolean doSearch = false;
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		if (searchType.equals("TYPE")) {
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "estTypeId";
			qp.value = " e.estTypeId=" + key;
			qp.dataType = 6;
			qp.logicType = 10;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("LEVEL")) {
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "estLevelId";
			qp.value = " e.estLevelId=" + key;
			qp.dataType = 6;
			qp.logicType = 10;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("BUS_TIME")) {
			c.setTime(new Date());
			c.add(5, 0 - Integer.parseInt(key));
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "busTime";
			qp.value = sf.format(c.getTime());
			qp.dataType = 4;
			qp.logicType = 2;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("COMM_TIME")) {
			c.setTime(new Date());
			c.add(5, 0 - Integer.parseInt(key));
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "commTime";
			qp.value = sf.format(c.getTime());
			qp.dataType = 4;
			qp.logicType = 2;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("NO_BUS")) {
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "busTime";
			qp.value = " (e.busTime is null)";
			qp.dataType = 6;
			qp.logicType = 10;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("NO_COMM")) {
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "commTime";
			qp.value = " (e.commTime is null)";
			qp.dataType = 6;
			qp.logicType = 10;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("UNABLED")) {
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "enabled";
			qp.value = " e.enabled=\'N\'";
			qp.dataType = 6;
			qp.logicType = 10;
			qpVe.add(qp);
			doSearch = true;
		} else if (searchType.equals("ALL")) {
			doSearch = true;
		}

		if (!searchType.equals("UNABLED") && !searchType.equals("ALL")
				|| estType.equals("PROVIDER") || estType.equals("COOPERATOR")) {
			qp = new QueryParameterCarrier();
			qp.objectName = estObjName;
			qp.propertyName = "enabled";
			qp.value = " e.enabled=\'Y\'";
			qp.dataType = 6;
			qp.logicType = 10;
			qpVe.add(qp);
		}

		if (doSearch) {
			QueryParameterCarrier[] qParas = new QueryParameterCarrier[qpVe
					.size()];

			for (int p1 = 0; p1 < qpVe.size(); ++p1) {
				qParas[p1] = (QueryParameterCarrier) qpVe.get(p1);
			}

			OrderParameterCarrier arg21 = new OrderParameterCarrier();
			arg21.objectName = conObjName;
			arg21.propertyName = "id";
			arg21.orderTarget = "asc";
			OrderParameterCarrier[] oParas = new OrderParameterCarrier[]{arg21};
			QueryResult qr = this.queryDao.doQuery(qParas, oParas,
					(String[]) null, shortNameMap, retObjs, (String[]) null);
			mv.addObject("contactList", qr.getList());
		}

		return mv;
	}

	public ModelAndView handleChangeTsForm(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.changeTsFormView);
		mv.addObject("idStr", request.getParameter("id_str"));
		mv.addObject("type", request.getParameter("type"));
		mv.addObject("tsList", this.tallySetDao.getList(true));
		return mv;
	}

	public ModelAndView handleChangeTs(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		boolean hasPrivilege = false;
		if (ub != null && ub.getUser() != null) {
			User tsId = ub.getUser();
			if (tsId.getUserType() == 1) {
				hasPrivilege = true;
			}
		}

		if (!hasPrivilege) {
			throw new Exception("Permission deny!");
		} else {
			String arg9 = request.getParameter("ts_id");
			String idStr = request.getParameter("id_str");
			String[] ids = idStr.split(";");
			long[] idArr = new long[ids.length];

			for (int mv = 0; mv < ids.length; ++mv) {
				idArr[mv] = Long.parseLong(ids[mv]);
			}

			this.establishmentDao.update(idArr, Long.parseLong(arg9));
			ModelAndView arg10 = new ModelAndView(
					"redirect:/ModalDialogSuccess.ihtm");
			arg10.addObject("returnValue", String.valueOf(ids.length));
			EncCommonHelper.setAlertMessage(request, "修改帐套成功！");
			return arg10;
		}
	}

	public ModelAndView handleEnabled(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String returnUrl = request.getParameter("from_url");
		ModelAndView mv = new ModelAndView("redirect:" + returnUrl);
		String id = request.getParameter("id");
		Establishment b = (Establishment) this.establishmentDao.get(
				Establishment.class, Long.parseLong(id));
		if (b != null) {
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			b.setEnabled("Y");
			b.setManagerId(ub.getStaffer().getId());
			b.setManagerName(ub.getStaffer().getStafferName());
			this.establishmentDao.update(b);
		}

		EncCommonHelper.setAlertMessage(request, "恢复成功！");
		return mv;
	}

	public ModelAndView handleLogList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.logListView);
		String estId = request.getParameter("est_id");
		mv.addObject(
				"est",
				this.establishmentDao.get(Establishment.class,
						Long.parseLong(estId)));
		mv.addObject("list",
				this.establishmentDao.getLogList(Long.parseLong(estId)));
		return mv;
	}

	public ModelAndView handleLogSearchResult(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "CLIE_LOG")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.logSearchResultView);
			String logObjName = "com.minierp.model.EstablishmentLog";
			String logObjShortName = "l";
			String estObjName = "com.minierp.model.Establishment";
			String estObjShortName = "e";
			HashMap shortNameMap = new HashMap();
			String[] retObjs = new String[]{logObjShortName};
			Vector qpVe = new Vector();
			HashMap parameters = new HashMap();
			shortNameMap.put(logObjName, logObjShortName);
			shortNameMap.put(estObjName, estObjShortName);
			String searchType = request.getParameter("search_type");
			String startDate = request.getParameter("start_date");
			String endDate = request.getParameter("end_date");
			String updName = request.getParameter("upd_name");
			String estName = request.getParameter("est_name");
			String estId = request.getParameter("est_id");
			String tsId = request.getParameter("ts_id");
			qpVe.add(new QueryParameterCarrier(logObjName, "estId",
					" l.estId=e.id", 6, 10));
			Date now = new Date();
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat shortSf = new SimpleDateFormat("yyyy-MM");
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			String qParas;
			if (searchType != null && !searchType.equals("")) {
				if (searchType.equals("2")) {
					qpVe.add(new QueryParameterCarrier(logObjName,
							"modifyTime", startDate, 4, 5));
					qpVe.add(new QueryParameterCarrier(logObjName,
							"modifyTime", EncCommonHelper.getNextDateStr(
									endDate, "yyyy-MM-dd"), 4, 2));
					qParas = EncCommonHelper.createTallySetSQLStr(
							"e.tallySetId", ub, false);
					if (qParas != null && !qParas.equals("")) {
						qpVe.add(new QueryParameterCarrier(estObjName,
								"tallySetId", qParas, 6, 10));
					}
				} else {
					qParas = request.getParameter("cb_upd_date");
					String p1 = request.getParameter("cb_upd");
					String oParas = request.getParameter("cb_est");
					String qr = request.getParameter("cb_ts");
					if (qr != null && qr.equals("1")) {
						qpVe.add(new QueryParameterCarrier(estObjName,
								"tallySetId", " e.tallySetId=" + tsId, 6, 10));
						parameters.put("cbTs", qr);
					} else {
						String tsHQL = EncCommonHelper.createTallySetSQLStr(
								"e.tallySetId", ub, false);
						if (tsHQL != null && !tsHQL.equals("")) {
							qpVe.add(new QueryParameterCarrier(estObjName,
									"tallySetId", tsHQL, 6, 10));
						}
					}

					if (qParas != null && qParas.equals("1")) {
						qpVe.add(new QueryParameterCarrier(logObjName,
								"modifyTime", startDate, 4, 5));
						qpVe.add(new QueryParameterCarrier(logObjName,
								"modifyTime", EncCommonHelper.getNextDateStr(
										endDate, "yyyy-MM-dd"), 4, 2));
						parameters.put("cbUpdDate", qParas);
					}

					if (oParas != null && oParas.equals("1")) {
						qpVe.add(new QueryParameterCarrier(logObjName, "estId",
								estId, 3, 1));
						parameters.put("cbEst", oParas);
					}

					if (p1 != null && p1.equals("1")) {
						qpVe.add(new QueryParameterCarrier(logObjName,
								"modifierName", updName, 1, 9));
						parameters.put("cbUpd", p1);
					}
				}
			} else {
				searchType = "2";
				startDate = shortSf.format(now) + "-01";
				endDate = sf.format(now);
				qpVe.add(new QueryParameterCarrier(logObjName, "modifyTime",
						startDate, 4, 5));
				qpVe.add(new QueryParameterCarrier(logObjName, "modifyTime",
						EncCommonHelper.getNextDateStr(endDate, "yyyy-MM-dd"),
						4, 2));
				qParas = EncCommonHelper.createTallySetSQLStr("e.tallySetId",
						ub, false);
				if (qParas != null && !qParas.equals("")) {
					qpVe.add(new QueryParameterCarrier(estObjName,
							"tallySetId", qParas, 6, 10));
				}
			}

			parameters.put("searchType", searchType);
			parameters.put("startDate", startDate);
			parameters.put("endDate", endDate);
			parameters.put("updName", updName);
			parameters.put("estName", estName);
			parameters.put("estId", estId);
			parameters.put("tsId", tsId);
			QueryParameterCarrier[] arg27 = new QueryParameterCarrier[qpVe
					.size()];

			for (int arg28 = 0; arg28 < qpVe.size(); ++arg28) {
				arg27[arg28] = (QueryParameterCarrier) qpVe.get(arg28);
			}

			OrderParameterCarrier arg29 = new OrderParameterCarrier();
			arg29.objectName = logObjName;
			arg29.propertyName = "id";
			arg29.orderTarget = "desc";
			OrderParameterCarrier[] arg30 = new OrderParameterCarrier[]{arg29};
			QueryResult arg31 = this.queryDao.doQuery(
					EncCommonHelper.getCurrentPageIndex(request),
					EncCommonHelper.getPageSize(request), arg27, arg30,
					(String[]) null, shortNameMap, retObjs, (String[]) null);
			mv.addObject("qr", arg31);
			mv.addAllObjects(parameters);
			mv.addObject("tsList",
					PageHelper.getTallySetList(this.tallySetDao, ub));
			return mv;
		}
	}

	public ModelAndView handleGetEstablishment(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String estName = request.getParameter("est_name");
		String estType = request.getParameter("est_type");
		Establishment est = this.establishmentDao.getEnabledByEstName(estName,
				estType);
		String estId = "0";
		if (est != null) {
			estId = String.valueOf(est.getId());
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ServletOutputStream out = response.getOutputStream();
		out.write(estId.getBytes());
		out.flush();
		out.close();
		return null;
	}

	public ModelAndView handleGetEstInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String estId = request.getParameter("est_id");
		Establishment est = (Establishment) this.establishmentDao.get(
				Establishment.class, Long.parseLong(estId));
		HashMap map = new HashMap();
		if (est != null) {
			EnterpriseInfo mapper = EncCommonHelper.getEnterpriseInfo(request);
			UserBean json = EncCommonHelper.getCurrentUserAccount(request);
			String out = "N";
			String baName = "";
			String baAccCode = "";
			String baAccName = "";
			if (mapper != null && json != null
					&& est.getEstType().equals("CLIENT")) {
				if (mapper.getSelectContact() != null
						&& mapper.getSelectContact().equals("ALL")) {
					out = "Y";
				} else if (est.getManagerId() == json.getStaffer().getId()) {
					out = "Y";
				} else {
					Staffer s = (Staffer) this.establishmentDao.get(
							Staffer.class, est.getManagerId());
					if (s != null
							&& s.getSuperiorIdStr() != null
							&& s.getSuperiorIdStr().indexOf(
									";" + json.getStaffer().getId() + ";") != -1) {
						out = "Y";
					} else {
						out = "N";
					}
				}
			}

			if (est.getBankName1() != null && !est.getBankName1().equals("")) {
				baName = est.getBankName1();
				if (est.getBankAccCode1() != null) {
					baAccCode = est.getBankAccCode1();
				}

				if (est.getBankAccName1() != null) {
					baAccName = est.getBankAccName1();
				}
			} else if (est.getBankName2() != null
					&& !est.getBankName2().equals("")) {
				baName = est.getBankName2();
				if (est.getBankAccCode2() != null) {
					baAccCode = est.getBankAccCode2();
				}

				if (est.getBankAccName2() != null) {
					baAccName = est.getBankAccName2();
				}
			}

			map.put("id", Long.valueOf(est.getId()));
			map.put("estName", est.getEstName());
			map.put("mngId", Long.valueOf(est.getManagerId()));
			map.put("mngName", est.getManagerName());
			map.put("canMng", out);
			map.put("phon", est.getPhone());
			map.put("addr", est.getAddress());
			map.put("lm", est.getLinkman());
			map.put("lmPhon", est.getLinkmanPhone());
			map.put("baName", baName);
			map.put("baAccCode", baAccCode);
			map.put("baAccName", baAccName);
			map.put("status", "OK");
			map.put("errMsg", "");
		} else {
			map.put("status", "ERROR");
			map.put("errMsg", "NOT FOUND");
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		String json1 = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json1.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleImpoForm(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.impoFormView);
		mv.addObject("type", request.getParameter("type"));
		return mv;
	}

	public ModelAndView handleImpo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String fileName = request.getParameter("file_name");
		String type = request.getParameter("type");
		File file = new File(this.getServletContext().getRealPath(fileName));
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String alertMsg = "";
		List etList = this.establishmentTypeDao.getList(true);
		List elList = this.establishmentLevelDao.getList(true);
		List areaList = this.areaDao.getList(true);
		List tsList = this.tallySetDao.getList(true);
		HashMap etMap = new HashMap();
		HashMap elMap = new HashMap();
		HashMap areaMap = new HashMap();
		String dataCode = "";
		String dataName = "";
		if (type.equals("CLIE")) {
			dataCode = "CLIENT";
			dataName = "客户";
		} else if (type.equals("COOP")) {
			dataCode = "COOPERATOR";
			dataName = "外协商";
		} else if (type.equals("PROV")) {
			dataCode = "PROVIDER";
			dataName = "供应商";
		}

		CodeRule estCr = this.codeRuleDao.get(dataCode);
		BufferedInputStream in = null;

		try {
			in = new BufferedInputStream(new FileInputStream(file));
			HSSFWorkbook out = new HSSFWorkbook(new POIFSFileSystem(in));
			int count = 0;
			String etName = "";
			String elName = "";
			HSSFSheet hssfsheet = out.getSheetAt(0);

			HSSFRow hssfrow;
			HSSFCell cell;
			String estName;
			String phon;
			String emai;
			String lm;
			String mark;
			for (int str = 1; str < hssfsheet.getPhysicalNumberOfRows(); ++str) {
				hssfrow = hssfsheet.getRow(str);
				if (hssfrow == null) {
					break;
				}

				boolean sex = false;
				byte poss = 0;
				cell = hssfrow.getCell((short) poss);
				String estCode = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(estCode);
				int arg68 = poss + 1;
				cell = hssfrow.getCell((short) arg68);
				estName = PageHelper.getCellVal(cell, 50);
				sex = sex || !PageHelper.isEmpty(estName);
				++arg68;
				if (type.equals("CLIE")) {
					cell = hssfrow.getCell((short) arg68);
					etName = PageHelper.getCellVal(cell, 15);
					sex = sex || !PageHelper.isEmpty(etName);
					++arg68;
					cell = hssfrow.getCell((short) arg68);
					elName = PageHelper.getCellVal(cell, 15);
					sex = sex || !PageHelper.isEmpty(elName);
					++arg68;
				}

				cell = hssfrow.getCell((short) arg68);
				phon = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(phon);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String fax = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(fax);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				emai = PageHelper.getCellVal(cell, 25);
				sex = sex || !PageHelper.isEmpty(emai);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String webSite = PageHelper.getCellVal(cell, 50);
				sex = sex || !PageHelper.isEmpty(webSite);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String areaName = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(areaName);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String postCode = PageHelper.getCellVal(cell, 10);
				sex = sex || !PageHelper.isEmpty(postCode);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String addr = PageHelper.getCellVal(cell, 50);
				sex = sex || !PageHelper.isEmpty(addr);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				lm = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(lm);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String lmPhon = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(lmPhon);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				mark = PageHelper.getCellVal(cell, 2000);
				sex = sex || !PageHelper.isEmpty(mark);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String mngName = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(mngName);
				++arg68;
				cell = hssfrow.getCell((short) arg68);
				String tsName = PageHelper.getCellVal(cell, 15);
				sex = sex || !PageHelper.isEmpty(tsName);
				++arg68;
				if (sex) {
					long mobi = 0L;
					long ecAlertMsg = 0L;
					long hasInput = 0L;
					long est = 0L;
					long tsId = 0L;
					boolean dataOk1 = true;
					Establishment s1;
					if (dataOk1) {
						if (estCode != null && !estCode.equals("")) {
							s1 = this.establishmentDao.getByEstCode(estCode,
									dataCode);
							if (s1 != null) {
								alertMsg = PageHelper.appendAlertMsg(alertMsg,
										"第" + str + "行：编号已经存在！");
								dataOk1 = false;
							}
						} else if (!estCr.getGenerateRule().equals("MANUAL")) {
							estCode = PageHelper.generateCode(
									this.serialNumberDao, estCr, "", 0L);

							for (s1 = this.establishmentDao.getByEstCode(
									estCode, dataCode); s1 != null; s1 = this.establishmentDao
									.getByEstCode(estCode, dataCode)) {
								estCode = PageHelper.generateCode(
										this.serialNumberDao, estCr, "", 0L);
							}
						} else {
							alertMsg = PageHelper.appendAlertMsg(alertMsg, "第"
									+ str + "行：编号规则必须设置为自动产生！");
							dataOk1 = false;
						}
					}

					if (dataOk1) {
						if (estName != null && !estName.equals("")) {
							s1 = this.establishmentDao.getByEstName(estName,
									dataCode);
							if (s1 != null) {
								alertMsg = PageHelper.appendAlertMsg(alertMsg,
										"第" + str + "行：名称已经存在！");
								dataOk1 = false;
							}
						} else {
							alertMsg = PageHelper.appendAlertMsg(alertMsg, "第"
									+ str + "行：名称不能为空！");
							dataOk1 = false;
						}
					}

					EstablishmentType sequCode;
					int arg75;
					if (dataOk1 && etName != null && !etName.trim().equals("")) {
						for (arg75 = 0; arg75 < etList.size(); ++arg75) {
							sequCode = (EstablishmentType) etList.get(arg75);
							if (sequCode.getTypeName().equals(etName)) {
								mobi = sequCode.getId();
								break;
							}
						}

						if (mobi == 0L && etMap.containsKey(etName)) {
							mobi = ((Long) etMap.get(etName)).longValue();
						}
					}

					EstablishmentLevel arg76;
					if (dataOk1 && elName != null && !elName.trim().equals("")) {
						for (arg75 = 0; arg75 < elList.size(); ++arg75) {
							arg76 = (EstablishmentLevel) elList.get(arg75);
							if (arg76.getLevelName().equals(elName)) {
								ecAlertMsg = arg76.getId();
								break;
							}
						}

						if (ecAlertMsg == 0L && elMap.containsKey(elName)) {
							ecAlertMsg = ((Long) elMap.get(elName)).longValue();
						}
					}

					if (dataOk1 && areaName != null
							&& !areaName.trim().equals("")) {
						for (arg75 = 0; arg75 < areaList.size(); ++arg75) {
							Area arg77 = (Area) areaList.get(arg75);
							if (arg77.getAreaName().equals(areaName)) {
								hasInput = arg77.getId();
								break;
							}
						}

						if (hasInput == 0L && areaMap.containsKey(areaName)) {
							hasInput = ((Long) areaMap.get(areaName))
									.longValue();
						}
					}

					if (dataOk1) {
						Staffer arg80;
						if (mngName != null && !mngName.trim().equals("")) {
							arg80 = this.stafferDao.getByName(mngName);
							if (arg80 != null) {
								est = arg80.getId();
							}
						}

						if (est == 0L) {
							arg80 = (Staffer) this.stafferDao.get(
									Staffer.class, -1L);
							if (arg80 != null) {
								est = arg80.getId();
								mngName = arg80.getStafferName();
							} else {
								alertMsg = PageHelper.appendAlertMsg(alertMsg,
										"第" + str + "行：经办人不存在，也没有系统管理员！");
								dataOk1 = false;
							}
						}
					}

					if (dataOk1) {
						if (tsName != null && !tsName.trim().equals("")) {
							for (arg75 = 0; arg75 < tsList.size(); ++arg75) {
								TallySet arg78 = (TallySet) tsList.get(arg75);
								if (arg78.getTitle().equals(tsName)) {
									tsId = arg78.getId();
									break;
								}
							}

							if (tsId == 0L) {
								alertMsg = PageHelper.appendAlertMsg(alertMsg,
										"第" + str + "行：帐套不存在！");
								dataOk1 = false;
							}
						} else if (tsList.size() > 0) {
							TallySet arg81 = (TallySet) tsList.get(0);
							tsId = arg81.getId();
						} else {
							alertMsg = PageHelper.appendAlertMsg(alertMsg, "第"
									+ str + "行：找不到缺省的帐套！");
							dataOk1 = false;
						}
					}

					if (dataOk1) {
						if (mobi == 0L && etName != null
								&& !etName.trim().equals("")) {
							arg75 = this.establishmentTypeDao
									.getMaxSequenceCode() + 1;
							sequCode = new EstablishmentType();
							sequCode.setSequenceCode(arg75);
							sequCode.setId(this.idGenerator
									.getId(EstablishmentType.class.getName()));
							sequCode.setTypeName(etName);
							this.establishmentDao.save(sequCode);
							mobi = sequCode.getId();
							etMap.put(etName, Long.valueOf(mobi));
						}

						if (ecAlertMsg == 0L && elName != null
								&& !elName.trim().equals("")) {
							arg75 = this.establishmentLevelDao
									.getMaxSequenceCode() + 1;
							arg76 = new EstablishmentLevel();
							arg76.setSequenceCode(arg75);
							arg76.setId(this.idGenerator
									.getId(EstablishmentLevel.class.getName()));
							arg76.setLevelName(elName);
							this.establishmentDao.save(arg76);
							ecAlertMsg = arg76.getId();
							elMap.put(elName, Long.valueOf(ecAlertMsg));
						}

						if (hasInput == 0L && areaName != null
								&& !areaName.trim().equals("")) {
							List arg82 = this.areaDao.getList(0L, true);
							String arg79 = String.valueOf(arg82.size() + 1);
							Area obj = new Area();
							obj.setSequCode(arg79);
							obj.setId(this.idGenerator.getId(Area.class
									.getName()));
							obj.setAreaName(areaName);
							this.establishmentDao.save(obj);
							hasInput = obj.getId();
							areaMap.put(areaName, Long.valueOf(hasInput));
						}

						s1 = new Establishment();
						s1.setId(this.idGenerator.getId(Establishment.class
								.getName()));
						s1.setAddress(addr);
						s1.setAreaId(hasInput);
						s1.setCreaterId(ub.getStaffer().getId());
						s1.setCreaterName(ub.getStaffer().getStafferName());
						s1.setEmail(emai);
						s1.setEstCode(estCode);
						s1.setEstLevelId(ecAlertMsg);
						s1.setEstName(estName);
						s1.setEstType(dataCode);
						s1.setEstTypeId(mobi);
						s1.setFax(fax);
						s1.setLinkman(lm);
						s1.setLinkmanPhone(lmPhon);
						s1.setManagerName(mngName);
						s1.setManagerId(est);
						s1.setMark(mark);
						s1.setNameSpell(PageHelper.getPinYinHeadChar(estName)
								.toUpperCase());
						s1.setPhone(phon);
						s1.setPostcode(postCode);
						s1.setTallySetId(tsId);
						s1.setWebSite(webSite);
						this.establishmentDao.save(s1);
						++count;
					}
				}
			}

			String arg67 = "<B>" + dataName + "成功导入" + count + "行</B>";
			if (alertMsg != null && !alertMsg.equals("")) {
				alertMsg = PageHelper.appendAlertMsg(arg67, alertMsg);
			} else {
				alertMsg = arg67;
			}

			if (out.getNumberOfSheets() > 1) {
				String arg71 = "";
				count = 0;
				hssfsheet = out.getSheetAt(1);

				for (int j = 1; j < hssfsheet.getPhysicalNumberOfRows(); ++j) {
					hssfrow = hssfsheet.getRow(j);
					if (hssfrow == null) {
						break;
					}

					boolean arg73 = false;
					cell = hssfrow.getCell(0);
					estName = PageHelper.getCellVal(cell, 50);
					arg73 = arg73 || !PageHelper.isEmpty(estName);
					cell = hssfrow.getCell(1);
					lm = PageHelper.getCellVal(cell, 15);
					arg73 = arg73 || !PageHelper.isEmpty(lm);
					cell = hssfrow.getCell(2);
					String arg70 = PageHelper.getCellVal(cell, 10);
					arg73 = arg73 || !PageHelper.isEmpty(arg70);
					cell = hssfrow.getCell(3);
					String arg72 = PageHelper.getCellVal(cell, 15);
					arg73 = arg73 || !PageHelper.isEmpty(arg72);
					cell = hssfrow.getCell(4);
					String arg69 = PageHelper.getCellVal(cell, 15);
					arg73 = arg73 || !PageHelper.isEmpty(arg69);
					cell = hssfrow.getCell(5);
					emai = PageHelper.getCellVal(cell, 25);
					arg73 = arg73 || !PageHelper.isEmpty(emai);
					cell = hssfrow.getCell(6);
					phon = PageHelper.getCellVal(cell, 15);
					arg73 = arg73 || !PageHelper.isEmpty(phon);
					cell = hssfrow.getCell(7);
					String im = PageHelper.getCellVal(cell, 25);
					arg73 = arg73 || !PageHelper.isEmpty(im);
					cell = hssfrow.getCell(8);
					mark = PageHelper.getCellVal(cell, 100);
					arg73 = arg73 || !PageHelper.isEmpty(mark);
					if (arg73) {
						boolean dataOk = true;
						Establishment arg74 = null;
						if (dataOk) {
							if (estName != null && !estName.trim().equals("")) {
								arg74 = this.establishmentDao.getByEstName(
										estName.trim(), dataCode);
								if (arg74 == null) {
									arg71 = PageHelper.appendAlertMsg(arg71,
											"第" + j + "行：" + dataName
													+ "名称不存在！");
									dataOk = false;
								}
							} else {
								arg71 = PageHelper.appendAlertMsg(arg71, "第"
										+ j + "行：" + dataName + "名称不能为空！");
								dataOk = false;
							}
						}

						if (dataOk && (lm == null || lm.trim().equals(""))) {
							arg71 = PageHelper.appendAlertMsg(arg71, "第" + j
									+ "行：姓名不能为空！");
							dataOk = false;
						}

						if (dataOk
								&& (arg69 == null || arg69.trim().equals(""))
								&& (phon == null || phon.trim().equals(""))) {
							arg71 = PageHelper.appendAlertMsg(arg71, "第" + j
									+ "行：手机和电话不能同时为空！");
							dataOk = false;
						}

						if (dataOk) {
							if (arg70 != null && arg70.equals("女")) {
								arg70 = "女";
							} else {
								arg70 = "男";
							}

							EstablishmentContact s = new EstablishmentContact();
							s.setContactName(lm);
							s.setEmail(emai);
							s.setEstId(arg74.getId());
							s.setId(this.idGenerator
									.getId(EstablishmentContact.class.getName()));
							s.setIm(im);
							s.setMark(mark);
							s.setMobile(arg69);
							s.setPhone(phon);
							s.setPossie(arg72);
							s.setSex(arg70);
							this.establishmentDao.save(s);
							if (arg74.getLinkman() == null
									|| arg74.getLinkman().equals("")) {
								arg74.setLinkman(s.getContactName());
								if (s.getMobile() != null
										&& !s.getMobile().trim().equals("")) {
									arg74.setLinkmanPhone(s.getMobile());
								} else {
									arg74.setLinkmanPhone(s.getPhone());
								}

								this.establishmentDao.update(arg74);
							}

							++count;
						}
					}
				}

				arg67 = "<B>联系人成功导入" + count + "行</B>";
				if (arg71 != null && !arg71.equals("")) {
					arg71 = PageHelper.appendAlertMsg(arg67, arg71);
				} else {
					arg71 = arg67;
				}

				alertMsg = PageHelper.appendAlertMsg(alertMsg, arg71);
			}
		} catch (Exception arg64) {
			alertMsg = "导入错误：" + arg64.getMessage();
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception arg63) {
				;
			}

		}

		EncCommonHelper.setAlertMessage(request, alertMsg);
		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ServletOutputStream arg66 = response.getOutputStream();
		arg66.write("OK".getBytes());
		arg66.flush();
		arg66.close();
		return null;
	}

	public ModelAndView handleBegiImpoForm(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.begiImpoFormView);
		mv.addObject("type", request.getParameter("type"));
		return mv;
	}

	public ModelAndView handleBegiImpo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String fileName = request.getParameter("file_name");
		String type = request.getParameter("type");
		File file = new File(this.getServletContext().getRealPath(fileName));
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		String alertMsg = "";
		boolean mtOk = true;
		long mtId = 0L;
		String dataCode = "";
		String dataName = "";
		String mtName = "期初欠款";
		CodeRule billCr;
		if (type.equals("CLIE")) {
			billCr = this.codeRuleDao.get("BUSINESS_BILL");
			dataCode = "CLIENT";
			dataName = "客户";
		} else if (type.equals("COOP")) {
			billCr = this.codeRuleDao.get("COOPER_BILL");
			dataCode = "COOPERATOR";
			dataName = "外协商";
		} else {
			if (!type.equals("PROV")) {
				throw new Exception("type " + type + " not supported!");
			}

			billCr = this.codeRuleDao.get("PURCHASE_BILL_BUY");
			dataCode = "PROVIDER";
			dataName = "供应商";
		}

		CodeRule estCr = this.codeRuleDao.get(dataCode);
		String dateStr;
		String arg61;
		if (!type.equals("CLIE") && !type.equals("COOP")) {
			if (type.equals("PROV")) {
				Product arg60 = this.productDao.getByName(mtName, true);
				if (arg60 != null) {
					mtId = arg60.getId();
				} else {
					arg61 = "QCQK-0000";
					if (mtOk) {
						mtId = this.idGenerator.getId(Product.class.getName());
						arg60 = new Product();
						arg60.setEnabled("N");
						arg60.setId(mtId);
						arg60.setPnSpell("QCQK");
						arg60.setProductCode(arg61);
						arg60.setProductName(mtName);
						this.productDao.save(arg60);
					}
				}
			}
		} else {
			MakeType out = this.makeTypeDao.getByName(mtName, true);
			if (out != null) {
				mtId = out.getId();
			} else {
				List costStr = this.makeTypeDao.getList(0L, true);
				dateStr = String.valueOf(costStr.size() + 1);
				mtId = this.idGenerator.getId(MakeType.class.getName());
				out = new MakeType();
				out.setSequCode(dateStr);
				out.setEnabled("N");
				out.setTnSpell("QCQK");
				out.setTypeName(mtName);
				out.setId(mtId);
				this.makeTypeDao.save(out);
			}
		}

		if (mtOk) {
			String shName = null;
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			List tsList = this.tallySetDao.getList(true);
			List shList = null;
			if (type.equals("PROV")) {
				shList = this.storehouseDao.getList(true);
			}

			EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
			BufferedInputStream in = null;

			try {
				in = new BufferedInputStream(new FileInputStream(file));
				HSSFWorkbook e = new HSSFWorkbook(new POIFSFileSystem(in));
				int count = 0;

				for (int str = 0; str < e.getNumberOfSheets(); ++str) {
					HSSFSheet hssfsheet = e.getSheetAt(str);

					for (int j = 1; j < hssfsheet.getPhysicalNumberOfRows(); ++j) {
						HSSFRow hssfrow = hssfsheet.getRow(j);
						if (hssfrow == null) {
							break;
						}

						boolean hasInput = false;
						HSSFCell cell = hssfrow.getCell(0);
						String arg62 = PageHelper.getCellVal(cell, 50);
						hasInput = hasInput || !PageHelper.isEmpty(arg62);
						cell = hssfrow.getCell(1);
						arg61 = PageHelper.getCellVal(cell, 0);
						hasInput = hasInput || !PageHelper.isEmpty(arg61);
						cell = hssfrow.getCell(2);
						dateStr = PageHelper.getCellVal(cell, 15);
						hasInput = hasInput || !PageHelper.isEmpty(dateStr);
						cell = hssfrow.getCell(3);
						String mark = PageHelper.getCellVal(cell, 200);
						hasInput = hasInput || !PageHelper.isEmpty(mark);
						cell = hssfrow.getCell(4);
						String tsName = PageHelper.getCellVal(cell, 15);
						hasInput = hasInput || !PageHelper.isEmpty(tsName);
						if (type.equals("PROV")) {
							cell = hssfrow.getCell(5);
							shName = PageHelper.getCellVal(cell, 15);
							hasInput = hasInput || !PageHelper.isEmpty(shName);
						}

						if (hasInput) {
							long estId = 0L;
							long tsId = 0L;
							long shId = 0L;
							String estCode = "";
							boolean dataOk = true;
							int arg65;
							if (dataOk) {
								if (tsName != null && !tsName.trim().equals("")) {
									for (arg65 = 0; arg65 < tsList.size(); ++arg65) {
										TallySet date = (TallySet) tsList
												.get(arg65);
										if (date.getTitle().equals(tsName)) {
											tsId = date.getId();
											break;
										}
									}

									if (tsId == 0L) {
										alertMsg = PageHelper.appendAlertMsg(
												alertMsg, "第" + j + "行：帐套不存在！");
										dataOk = false;
									}
								} else if (tsList.size() > 0) {
									TallySet cost = (TallySet) tsList.get(0);
									tsId = cost.getId();
								} else {
									alertMsg = PageHelper.appendAlertMsg(
											alertMsg, "第" + j + "行：找不到缺省的帐套！");
									dataOk = false;
								}
							}

							if (dataOk && type.equals("PROV")) {
								if (shName != null && !shName.trim().equals("")) {
									for (arg65 = 0; arg65 < shList.size(); ++arg65) {
										Storehouse arg67 = (Storehouse) shList
												.get(arg65);
										if (arg67.getStoName().equals(shName)) {
											shId = arg67.getId();
											break;
										}
									}

									if (shId == 0L) {
										alertMsg = PageHelper.appendAlertMsg(
												alertMsg, "第" + j + "行：仓库不存在！");
										dataOk = false;
									}
								} else if (shList.size() > 0) {
									Storehouse arg66 = (Storehouse) shList
											.get(0);
									shId = arg66.getId();
								} else {
									alertMsg = PageHelper.appendAlertMsg(
											alertMsg, "第" + j + "行：找不到缺省的仓库！");
									dataOk = false;
								}
							}

							if (dataOk) {
								if (arg62 != null && !arg62.equals("")) {
									Establishment arg69 = this.establishmentDao
											.getByEstName(arg62, dataCode);
									if (arg69 != null) {
										estId = arg69.getId();
									} else {
										if (!estCr.getGenerateRule().equals(
												"MANUAL")) {
											estCode = PageHelper.generateCode(
													this.serialNumberDao,
													estCr, "", 0L);

											for (Establishment arg68 = this.establishmentDao
													.getByEstCode(estCode,
															dataCode); arg68 != null; arg68 = this.establishmentDao
													.getByEstCode(estCode,
															dataCode)) {
												estCode = PageHelper
														.generateCode(
																this.serialNumberDao,
																estCr, "", 0L);
											}
										} else {
											alertMsg = PageHelper
													.appendAlertMsg(
															alertMsg,
															"第"
																	+ j
																	+ "行："
																	+ dataName
																	+ "编号规则必须设置为自动产生！");
											dataOk = false;
										}

										if (dataOk) {
											estId = this.idGenerator
													.getId(Establishment.class
															.getName());
											arg69 = new Establishment();
											arg69.setCreaterId(ub.getStaffer()
													.getId());
											arg69.setCreaterName(ub
													.getStaffer()
													.getStafferName());
											arg69.setEstCode(estCode);
											arg69.setEstName(arg62);
											arg69.setEstType(dataCode);
											arg69.setId(estId);
											arg69.setManagerId(ub.getStaffer()
													.getId());
											arg69.setManagerName(ub
													.getStaffer()
													.getStafferName());
											arg69.setNameSpell(PageHelper
													.getPinYinHeadChar(arg62)
													.toUpperCase());
											arg69.setTallySetId(tsId);
											this.establishmentDao.save(arg69);
										}
									}
								} else {
									alertMsg = PageHelper.appendAlertMsg(
											alertMsg, "第" + j + "行：名称不能为空！");
									dataOk = false;
								}
							}

							BigDecimal arg72 = new BigDecimal(0);
							if (dataOk) {
								if (arg61 != null && !arg61.equals("")) {
									try {
										arg72 = (new BigDecimal(arg61))
												.setScale(2, 4);
									} catch (Exception arg57) {
										alertMsg = PageHelper.appendAlertMsg(
												alertMsg, "第" + j
														+ "行：欠款金额只能是数字！");
										dataOk = false;
									}
								} else {
									alertMsg = PageHelper.appendAlertMsg(
											alertMsg, "第" + j + "行：欠款金额不能为空！");
									dataOk = false;
								}
							}

							Date arg70 = null;
							if (dataOk) {
								if (dateStr != null && !dateStr.equals("")) {
									try {
										arg70 = sf.parse(dateStr);
									} catch (Exception arg56) {
										alertMsg = PageHelper.appendAlertMsg(
												alertMsg, "第" + j
														+ "行：截止日期格式错误！");
										dataOk = false;
									}
								} else {
									alertMsg = PageHelper.appendAlertMsg(
											alertMsg, "第" + j + "行：截止日期不能为空！");
									dataOk = false;
								}
							}

							if (dataOk) {
								if (type.equals("CLIE")) {
									BusinessBill b = new BusinessBill();
									b.setAmount(new BigDecimal(1));
									b.setCheckDate(arg70);
									b.setClientId(estId);
									b.setContent("截止至" + dateStr + "的欠款");
									b.setCost(arg72);
									b.setCreaterId(ub.getStaffer().getId());
									b.setCreaterName(ub.getStaffer()
											.getStafferName());
									b.setDeliverDate(arg70);
									b.setOrderDate(arg70);
									b.setTallySetId(tsId);
									BusinessBillItem item = new BusinessBillItem();
									item.setAmount(new BigDecimal(1));
									item.setCost(arg72);
									item.setMakeTypeId(mtId);
									item.setPriceType("AMOUNT");
									item.setUnitPrice(arg72);
									item.setFinishedContent(mark);
									this.businessBillService
											.txInsertForBegiImpo(b, billCr,
													item, ent, ub,
													this.businessBillDao,
													this.stockDao,
													this.serialNumberDao,
													this.idGenerator);
								} else if (type.equals("COOP")) {
									CooperBill arg71 = new CooperBill();
									arg71.setAmount(new BigDecimal(0));
									arg71.setContent("截止至" + dateStr + "的欠款");
									arg71.setCooperatorId(estId);
									arg71.setCooperDate(arg70);
									arg71.setCost(arg72);
									arg71.setCreaterId(ub.getStaffer().getId());
									arg71.setCreaterName(ub.getStaffer()
											.getStafferName());
									arg71.setGatherDate(arg70);
									arg71.setTallySetId(tsId);
									arg71.setManagerName("");
									CooperBillItem arg74 = new CooperBillItem();
									arg74.setAmount(new BigDecimal(1));
									arg74.setCost(arg72);
									arg74.setMakeTypeId(mtId);
									arg74.setPriceType("AMOUNT");
									arg74.setUnitPrice(arg72);
									arg74.setFinishedContent(mark);
									arg74.setGatheredAmount(arg74.getAmount());
									this.cooperBillService.txInsertForBegiImpo(
											arg71, billCr, arg74, ent, ub,
											this.cooperBillDao,
											this.serialNumberDao,
											this.idGenerator);
								} else if (type.equals("PROV")) {
									PurchaseBill arg73 = new PurchaseBill();
									arg73.setBillType("BUY");
									arg73.setContent("截止至" + dateStr + "的欠款");
									arg73.setProviderId(estId);
									arg73.setPurchaseDate(arg70);
									arg73.setCost(arg72);
									arg73.setCreaterId(ub.getStaffer().getId());
									arg73.setCreaterName(ub.getStaffer()
											.getStafferName());
									arg73.setTallySetId(tsId);
									arg73.setStorehouseId(shId);
									arg73.setManagerName("");
									PurchaseBillItem arg75 = new PurchaseBillItem();
									arg75.setAmount(new BigDecimal(1));
									arg75.setCost(arg72);
									arg75.setProductId(mtId);
									arg75.setUnitPrice(arg72);
									this.purchaseBillService
											.txInsertForBegiImpo(arg73, billCr,
													arg75, ub, arg62, ent,
													this.purchaseBillDao,
													this.stockDao,
													this.stockBalanceDao,
													this.serialNumberDao,
													this.idGenerator);
								}

								++count;
							}
						}
					}
				}

				String arg64 = "<B>成功导入" + count + "行</B>";
				if (alertMsg != null && !alertMsg.equals("")) {
					alertMsg = PageHelper.appendAlertMsg(arg64, alertMsg);
				} else {
					alertMsg = arg64;
				}
			} catch (Exception arg58) {
				arg58.printStackTrace();
				alertMsg = "导入错误：" + arg58.getMessage();
			} finally {
				try {
					if (in != null) {
						in.close();
					}
				} catch (Exception arg55) {
					;
				}

			}
		}

		EncCommonHelper.setAlertMessage(request, alertMsg);
		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ServletOutputStream arg63 = response.getOutputStream();
		arg63.write("OK".getBytes());
		arg63.flush();
		arg63.close();
		return null;
	}

	public ModelAndView handleContAdd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String estId = request.getParameter("est_id");
		String linkman = request.getParameter("linkman");
		String phone = request.getParameter("phone");
		boolean dataOk = true;
		String msg = "OK";
		if (estId != null && !estId.equals("") && !estId.equals("0")) {
			if (linkman != null && !linkman.equals("")) {
				if (phone == null || phone.equals("")) {
					dataOk = false;
					msg = "PHONE_ERR";
				}
			} else {
				dataOk = false;
				msg = "LINKMAN_ERR";
			}
		} else {
			dataOk = false;
			msg = "EST_ID_ERR";
		}

		if (dataOk) {
			List out = this.establishmentContactDao.getList(Long
					.parseLong(estId));
			boolean updaEstLinkman = false;
			boolean found = false;
			if (out.isEmpty()) {
				updaEstLinkman = true;
			} else {
				for (int c = 0; c < out.size(); ++c) {
					EstablishmentContact est = (EstablishmentContact) out
							.get(c);
					if (est.getContactName().equals(linkman)) {
						found = true;
						break;
					}
				}
			}

			if (found) {
				msg = "CONT_EXIST";
			} else {
				EstablishmentContact arg13 = new EstablishmentContact();
				arg13.setContactName(linkman);
				arg13.setEstId(Long.parseLong(estId));
				arg13.setPhone(phone);
				arg13.setSex("男");
				arg13.setId(this.idGenerator.getId(EstablishmentContact.class
						.getName()));
				this.establishmentDao.save(arg13);
				if (updaEstLinkman) {
					Establishment arg14 = (Establishment) this.establishmentDao
							.get(Establishment.class, arg13.getEstId());
					arg14.setLinkman(arg13.getContactName());
					arg14.setLinkmanPhone(arg13.getMobile());
					this.establishmentDao.update(arg14);
				}
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ServletOutputStream arg12 = response.getOutputStream();
		arg12.write(msg.getBytes());
		arg12.flush();
		arg12.close();
		return null;
	}

	public ModelAndView handleAppList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				String mapper = "CLIENT";
				json = request.getParameter("est_name");
				String out = request.getParameter("phon");
				String addr = request.getParameter("addr");
				String orde = request.getParameter("orde");
				String showPrev = request.getParameter("show_prev");
				boolean checkTs = true;
				EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
				if (ent.getBaseTs() == null || !ent.getBaseTs().equals("Y")) {
					checkTs = false;
				}

				int total = this.establishmentDao.getAppListCount(mapper, json,
						out, addr, checkTs, ub);
				int perPageNum = EncCommonHelper.getPageSize(request);
				int pageno = EncCommonHelper.getCurrentPageIndex(request,
						total, perPageNum);
				if (total > pageno * perPageNum) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				List list;
				if (showPrev != null && showPrev.equals("Y")) {
					list = this.establishmentDao.getAppList(mapper, json, out,
							addr, checkTs, ub, orde, 0, pageno * perPageNum);
				} else {
					list = this.establishmentDao.getAppList(mapper, json, out,
							addr, checkTs, ub, orde, (pageno - 1) * perPageNum,
							perPageNum);
				}

				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfl = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				ArrayList items = new ArrayList();

				for (int i = 0; i < list.size(); ++i) {
					HashMap item = new HashMap();
					Establishment e = (Establishment) list.get(i);
					String commTime = "";
					String creaTime = "";
					if (e.getCommTime() != null) {
						commTime = sf.format(e.getCommTime());
					}

					if (e.getCreateTime() != null) {
						creaTime = sfl.format(e.getCreateTime());
					}

					item.put("id", Long.valueOf(e.getId()));
					item.put("estName", e.getEstName());
					item.put("phon", PageHelper.parseNull(e.getPhone()));
					item.put("addr", PageHelper.parseNull(e.getAddress()));
					item.put("lm", PageHelper.parseNull(e.getLinkman()));
					item.put("lmPhon",
							PageHelper.parseNull(e.getLinkmanPhone()));
					item.put("commTime", commTime);
					item.put("mngName", e.getManagerName());
					item.put("creaTime", creaTime);
					items.add(item);
				}

				map.put("items", items);
				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg25) {
				map.put("status", "ERROR");
				map.put("errMsg", arg25.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg26 = new ObjectMapper();
		json = arg26.writeValueAsString(map);
		ServletOutputStream arg27 = response.getOutputStream();
		arg27.write(json.getBytes("utf-8"));
		arg27.flush();
		arg27.close();
		return null;
	}

	public ModelAndView handleAppInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				String mapper = request.getParameter("id");
				if (mapper == null) {
					mapper = "";
				}

				json = "";
				if (mapper != null && !mapper.equals("")) {
					Establishment out = (Establishment) this.establishmentDao
							.get(Establishment.class, Long.parseLong(mapper));
					List types = this.establishmentContactDao.getList(out
							.getId());
					map.put("estName", out.getEstName());
					map.put("typeId", Long.valueOf(out.getEstTypeId()));
					map.put("leveId", Long.valueOf(out.getEstLevelId()));
					map.put("phon", PageHelper.parseNull(out.getPhone()));
					map.put("fax", PageHelper.parseNull(out.getFax()));
					map.put("mail", PageHelper.parseNull(out.getEmail()));
					map.put("webSite", PageHelper.parseNull(out.getWebSite()));
					map.put("postCode", PageHelper.parseNull(out.getPostcode()));
					map.put("areaId", Long.valueOf(out.getAreaId()));
					map.put("addr", PageHelper.parseNull(out.getAddress()));
					map.put("mark", PageHelper.parseNull(out.getMark()));
					ArrayList leveList = new ArrayList();

					for (int leves = 0; leves < types.size(); ++leves) {
						EstablishmentContact areaList = (EstablishmentContact) types
								.get(leves);
						HashMap areas = new HashMap();
						areas.put("name",
								PageHelper.parseNull(areaList.getContactName()));
						areas.put("sex",
								PageHelper.parseNull(areaList.getSex()));
						areas.put("poss",
								PageHelper.parseNull(areaList.getPossie()));
						areas.put("mobi",
								PageHelper.parseNull(areaList.getMobile()));
						areas.put("mail",
								PageHelper.parseNull(areaList.getEmail()));
						areas.put("phon",
								PageHelper.parseNull(areaList.getPhone()));
						areas.put("im", PageHelper.parseNull(areaList.getIm()));
						areas.put("mark",
								PageHelper.parseNull(areaList.getMark()));
						areas.put("id", Long.valueOf(areaList.getId()));
						leveList.add(areas);
					}

					map.put("conts", leveList);
				} else {
					json = ub.getUser().getId() + "_"
							+ System.currentTimeMillis();
				}

				List arg18 = this.establishmentTypeDao.getList(true);
				ArrayList arg20 = new ArrayList();

				for (int arg21 = 0; arg21 < arg18.size(); ++arg21) {
					EstablishmentType arg23 = (EstablishmentType) arg18
							.get(arg21);
					HashMap arg25 = new HashMap();
					arg25.put("id", Long.valueOf(arg23.getId()));
					arg25.put("name", arg23.getTypeName());
					arg20.add(arg25);
				}

				map.put("types", arg20);
				List arg22 = this.establishmentLevelDao.getList(true);
				ArrayList arg24 = new ArrayList();

				for (int arg26 = 0; arg26 < arg22.size(); ++arg26) {
					EstablishmentLevel arg28 = (EstablishmentLevel) arg22
							.get(arg26);
					HashMap i = new HashMap();
					i.put("id", Long.valueOf(arg28.getId()));
					i.put("name", arg28.getLevelName());
					arg24.add(i);
				}

				map.put("leves", arg24);
				List arg27 = PageHelper.createTreeArray(
						this.areaDao.getList(true), "--", true);
				ArrayList arg29 = new ArrayList();

				for (int arg30 = 0; arg30 < arg27.size(); ++arg30) {
					String[] objs = (String[]) arg27.get(arg30);
					HashMap item = new HashMap();
					item.put("id", objs[0]);
					item.put("name", objs[1]);
					arg29.add(item);
				}

				map.put("areas", arg29);
				map.put("tmpCode", json);
				map.put("id", mapper);
				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg16) {
				map.put("status", "ERROR");
				map.put("errMsg", arg16.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg17 = new ObjectMapper();
		json = arg17.writeValueAsString(map);
		ServletOutputStream arg19 = response.getOutputStream();
		arg19.write(json.getBytes("utf-8"));
		arg19.flush();
		arg19.close();
		return null;
	}

	public ModelAndView handleAppContEdit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				String mapper = request.getParameter("id");
				json = request.getParameter("est_id");
				String out = request.getParameter("tmp_code");
				String name = request.getParameter("name");
				String sex = request.getParameter("sex");
				String poss = request.getParameter("poss");
				String mail = request.getParameter("mail");
				String mobi = request.getParameter("mobi");
				String phon = request.getParameter("phon");
				String im = request.getParameter("im");
				String mark = request.getParameter("mark");
				if (!sex.equals("女")) {
					sex = "男";
				}

				EstablishmentContact c;
				List list;
				if (mapper != null && !mapper.equals("") && !mapper.equals("0")) {
					c = (EstablishmentContact) this.establishmentContactDao
							.get(EstablishmentContact.class,
									Long.parseLong(mapper));
					if (c != null) {
						c.setContactName(name);
						c.setPossie(poss);
						c.setPhone(phon);
						c.setEmail(mail);
						c.setMobile(mobi);
						c.setMark(mark);
						c.setIm(im);
						c.setSex(sex);
						this.establishmentContactDao.update(c);
						if (json != null && !json.equals("")) {
							list = this.establishmentContactDao.getList(Long
									.parseLong(json));
							if (list.size() > 0) {
								EstablishmentContact est2 = (EstablishmentContact) list
										.get(0);
								if (est2.getId() == c.getId()) {
									Establishment est1 = (Establishment) this.establishmentDao
											.get(Establishment.class,
													Long.parseLong(json));
									est1.setLinkman(name);
									est1.setLinkmanPhone(mobi);
									this.establishmentDao.update(est1);
								}
							}
						}
					}
				} else {
					c = new EstablishmentContact();
					c.setContactName(name);
					c.setPossie(poss);
					c.setPhone(phon);
					c.setEmail(mail);
					c.setMobile(mobi);
					c.setMark(mark);
					c.setIm(im);
					c.setSex(sex);
					c.setId(this.idGenerator.getId(EstablishmentContact.class
							.getName()));
					if (json != null && !json.equals("")) {
						c.setEstId(Long.parseLong(json));
					} else {
						c.setTmpCode(out);
					}

					this.establishmentDao.save(c);
					if (json != null && !json.equals("")) {
						list = this.establishmentContactDao.getList(Long
								.parseLong(json));
						if (list.size() == 1) {
							Establishment est = (Establishment) this.establishmentDao
									.get(Establishment.class,
											Long.parseLong(json));
							est.setLinkman(name);
							est.setLinkmanPhone(mobi);
							this.establishmentDao.update(est);
						}
					}

					map.put("id", Long.valueOf(c.getId()));
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg20) {
				map.put("status", "ERROR");
				map.put("errMsg", arg20.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		json = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppEdit(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				String mapper = request.getParameter("est_id");
				json = request.getParameter("tmp_code");
				String out = request.getParameter("name");
				String phon = request.getParameter("phon");
				String fax = request.getParameter("fax");
				String mail = request.getParameter("mail");
				String webSite = request.getParameter("web_site");
				String postCode = request.getParameter("post_code");
				String addr = request.getParameter("addr");
				String mark = request.getParameter("mark");
				String typeId = request.getParameter("type_id");
				String leveId = request.getParameter("leve_id");
				String areaId = request.getParameter("area_id");
				if (typeId == null || typeId.equals("")) {
					typeId = "0";
				}

				if (leveId == null || leveId.equals("")) {
					leveId = "0";
				}

				if (areaId == null || areaId.equals("")) {
					areaId = "0";
				}

				String dataCode = "CLIENT";
				Establishment c = this.establishmentDao.getByEstName(out,
						dataCode);
				if (mapper != null && !mapper.equals("")) {
					if (c == null) {
						c = (Establishment) this.establishmentDao.get(
								Establishment.class, Long.parseLong(mapper));
					} else if (c.getId() != Long.parseLong(mapper)) {
						throw new Exception("客户名称已经存在！");
					}

					c.setEstName(out);
					c.setFax(fax);
					c.setPhone(phon);
					c.setEmail(mail);
					c.setWebSite(webSite);
					c.setPostcode(postCode);
					c.setAddress(addr);
					c.setMark(mark);
					c.setEstTypeId(Long.parseLong(typeId));
					c.setEstLevelId(Long.parseLong(leveId));
					c.setAreaId(Long.parseLong(areaId));
					this.establishmentDao.update(c);
				} else {
					if (ub.getUser().getDfTsId() == 0L) {
						throw new Exception("请先设置当前帐套！");
					}

					if (c != null) {
						throw new Exception("客户名称已经存在！");
					}

					CodeRule estCr = this.codeRuleDao.get(dataCode);
					String estCode = "";
					if (estCr.getGenerateRule().equals("MANUAL")) {
						throw new Exception("客户编号规则必须设置为自动产生！");
					}

					estCode = PageHelper.generateCode(this.serialNumberDao,
							estCr, "", 0L);

					for (Establishment id = this.establishmentDao.getByEstCode(
							estCode, dataCode); id != null; id = this.establishmentDao
							.getByEstCode(estCode, dataCode)) {
						estCode = PageHelper.generateCode(this.serialNumberDao,
								estCr, "", 0L);
					}

					long id1 = this.idGenerator.getId(Establishment.class
							.getName());
					this.establishmentContactDao.updateTmpCode(json, id1);
					String linkman = "";
					String linkmanPhone = "";
					List list = this.establishmentContactDao.getList(id1);
					if (list.size() > 0) {
						EstablishmentContact ec = (EstablishmentContact) list
								.get(0);
						linkman = ec.getContactName();
						linkmanPhone = ec.getMobile();
					}

					c = new Establishment();
					c.setId(id1);
					c.setEstCode(estCode);
					c.setTallySetId(ub.getUser().getDfTsId());
					c.setCreaterId(ub.getStaffer().getId());
					c.setCreaterName(ub.getStaffer().getStafferName());
					c.setEstType(dataCode);
					c.setManagerId(ub.getStaffer().getId());
					c.setManagerName(ub.getStaffer().getStafferName());
					c.setNameSpell(PageHelper.getPinYinHeadChar(out)
							.toUpperCase());
					c.setLinkman(linkman);
					c.setLinkmanPhone(linkmanPhone);
					c.setEstName(out);
					c.setFax(fax);
					c.setPhone(phon);
					c.setEmail(mail);
					c.setWebSite(webSite);
					c.setPostcode(postCode);
					c.setAddress(addr);
					c.setMark(mark);
					c.setEstTypeId(Long.parseLong(typeId));
					c.setEstLevelId(Long.parseLong(leveId));
					c.setAreaId(Long.parseLong(areaId));
					this.establishmentDao.save(c);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg28) {
				map.put("status", "ERROR");
				map.put("errMsg", arg28.getMessage());
				arg28.printStackTrace();
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		json = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public ModelAndView handleAppContInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				String mapper = request.getParameter("id");
				EstablishmentContact json = (EstablishmentContact) this.establishmentContactDao
						.get(EstablishmentContact.class, Long.parseLong(mapper));
				if (json != null) {
					map.put("name", json.getContactName());
					map.put("sex", json.getSex());
					map.put("poss", json.getPossie());
					map.put("mail", json.getEmail());
					map.put("mobi", json.getMobile());
					map.put("phon", json.getPhone());
					map.put("im", json.getIm());
					map.put("mark", json.getMark());
					map.put("status", "OK");
					map.put("errMsg", "");
				} else {
					map.put("status", "ERROR");
					map.put("errMsg", "找不到该联系人资料");
				}
			} catch (Exception arg8) {
				map.put("status", "ERROR");
				map.put("errMsg", arg8.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		String json1 = mapper1.writeValueAsString(map);
		ServletOutputStream out = response.getOutputStream();
		out.write(json1.getBytes("utf-8"));
		out.flush();
		out.close();
		return null;
	}

	public ModelAndView handleAppContDele(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				String mapper = request.getParameter("id");
				json = request.getParameter("est_id");
				this.establishmentContactDao.delete(Long.parseLong(mapper));
				if (json != null && !json.equals("")) {
					Establishment out = (Establishment) this.establishmentDao
							.get(Establishment.class, Long.parseLong(json));
					List list = this.establishmentContactDao.getList(Long
							.parseLong(json));
					if (list.size() > 0) {
						EstablishmentContact firCont = (EstablishmentContact) list
								.get(0);
						out.setLinkman(firCont.getContactName());
						out.setLinkmanPhone(firCont.getMobile());
					} else {
						out.setLinkman("");
						out.setLinkmanPhone("");
					}

					this.establishmentDao.update(out);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg10) {
				map.put("status", "ERROR");
				map.put("errMsg", arg10.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper mapper1 = new ObjectMapper();
		json = mapper1.writeValueAsString(map);
		ServletOutputStream out1 = response.getOutputStream();
		out1.write(json.getBytes("utf-8"));
		out1.flush();
		out1.close();
		return null;
	}

	public String getListForSelectView() {
		return this.listForSelectView;
	}

	public void setListForSelectView(String listForSelectView) {
		this.listForSelectView = listForSelectView;
	}

	public EstablishmentContactDao getEstablishmentContactDao() {
		return this.establishmentContactDao;
	}

	public void setEstablishmentContactDao(
			EstablishmentContactDao establishmentContactDao) {
		this.establishmentContactDao = establishmentContactDao;
	}

	public EstablishmentDao getEstablishmentDao() {
		return this.establishmentDao;
	}

	public void setEstablishmentDao(EstablishmentDao establishmentDao) {
		this.establishmentDao = establishmentDao;
	}

	public String getCheckView() {
		return this.checkView;
	}

	public void setCheckView(String checkView) {
		this.checkView = checkView;
	}

	public String getManageListView() {
		return this.manageListView;
	}

	public void setManageListView(String manageListView) {
		this.manageListView = manageListView;
	}

	public AreaDao getAreaDao() {
		return this.areaDao;
	}

	public void setAreaDao(AreaDao areaDao) {
		this.areaDao = areaDao;
	}

	public EstablishmentLevelDao getEstablishmentLevelDao() {
		return this.establishmentLevelDao;
	}

	public void setEstablishmentLevelDao(
			EstablishmentLevelDao establishmentLevelDao) {
		this.establishmentLevelDao = establishmentLevelDao;
	}

	public EstablishmentTypeDao getEstablishmentTypeDao() {
		return this.establishmentTypeDao;
	}

	public void setEstablishmentTypeDao(
			EstablishmentTypeDao establishmentTypeDao) {
		this.establishmentTypeDao = establishmentTypeDao;
	}

	public String getContactListForSelectView() {
		return this.contactListForSelectView;
	}

	public void setContactListForSelectView(String contactListForSelectView) {
		this.contactListForSelectView = contactListForSelectView;
	}

	public String getContactSelectForSmsView() {
		return this.contactSelectForSmsView;
	}

	public void setContactSelectForSmsView(String contactSelectForSmsView) {
		this.contactSelectForSmsView = contactSelectForSmsView;
	}

	public QueryDao getQueryDao() {
		return this.queryDao;
	}

	public void setQueryDao(QueryDao queryDao) {
		this.queryDao = queryDao;
	}

	public String getMoveSimpleFormView() {
		return this.moveSimpleFormView;
	}

	public void setMoveSimpleFormView(String moveSimpleFormView) {
		this.moveSimpleFormView = moveSimpleFormView;
	}

	public AdjustBillDao getAdjustBillDao() {
		return this.adjustBillDao;
	}

	public void setAdjustBillDao(AdjustBillDao adjustBillDao) {
		this.adjustBillDao = adjustBillDao;
	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}

	public EstablishmentCommunicateDao getEstablishmentCommunicateDao() {
		return this.establishmentCommunicateDao;
	}

	public void setEstablishmentCommunicateDao(
			EstablishmentCommunicateDao establishmentCommunicateDao) {
		this.establishmentCommunicateDao = establishmentCommunicateDao;
	}

	public EstablishmentService getEstablishmentService() {
		return this.establishmentService;
	}

	public void setEstablishmentService(
			EstablishmentService establishmentService) {
		this.establishmentService = establishmentService;
	}

	public InBillDao getInBillDao() {
		return this.inBillDao;
	}

	public void setInBillDao(InBillDao inBillDao) {
		this.inBillDao = inBillDao;
	}

	public OutBillDao getOutBillDao() {
		return this.outBillDao;
	}

	public void setOutBillDao(OutBillDao outBillDao) {
		this.outBillDao = outBillDao;
	}

	public ReceiveBillDao getReceiveBillDao() {
		return this.receiveBillDao;
	}

	public void setReceiveBillDao(ReceiveBillDao receiveBillDao) {
		this.receiveBillDao = receiveBillDao;
	}

	public String getChangeTsFormView() {
		return this.changeTsFormView;
	}

	public void setChangeTsFormView(String changeTsFormView) {
		this.changeTsFormView = changeTsFormView;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public AccessoryDao getAccessoryDao() {
		return this.accessoryDao;
	}

	public void setAccessoryDao(AccessoryDao accessoryDao) {
		this.accessoryDao = accessoryDao;
	}

	public String getClientListView() {
		return this.clientListView;
	}

	public void setClientListView(String clientListView) {
		this.clientListView = clientListView;
	}

	public String getCooperatorListView() {
		return this.cooperatorListView;
	}

	public void setCooperatorListView(String cooperatorListView) {
		this.cooperatorListView = cooperatorListView;
	}

	public String getProviderListView() {
		return this.providerListView;
	}

	public void setProviderListView(String providerListView) {
		this.providerListView = providerListView;
	}

	public String getListForPriceView() {
		return this.listForPriceView;
	}

	public void setListForPriceView(String listForPriceView) {
		this.listForPriceView = listForPriceView;
	}

	public FinanceDetailDao getFinanceDetailDao() {
		return this.financeDetailDao;
	}

	public void setFinanceDetailDao(FinanceDetailDao financeDetailDao) {
		this.financeDetailDao = financeDetailDao;
	}

	public String getListForCooperPriceView() {
		return this.listForCooperPriceView;
	}

	public void setListForCooperPriceView(String listForCooperPriceView) {
		this.listForCooperPriceView = listForCooperPriceView;
	}

	public EstPriceDao getEstPriceDao() {
		return this.estPriceDao;
	}

	public void setEstPriceDao(EstPriceDao estPriceDao) {
		this.estPriceDao = estPriceDao;
	}

	public PayBillDao getPayBillDao() {
		return this.payBillDao;
	}

	public void setPayBillDao(PayBillDao payBillDao) {
		this.payBillDao = payBillDao;
	}
}